Solved

Using variables within XSL Output

Posted on 2003-10-28
7
243 Views
Last Modified: 2010-04-17
Hi,

I would ask this directly in the XML section but the link doesnt appear to be working.

I have the following piece of XSL code which embeds an SVG image within my document:

<xsl:for-each select="Diagram">
      <embed height="163.8"  width="172.20">
      <xsl:attribute name="id">SVGDiagram</xsl:attribute>
      <xsl:attribute name="src"><xsl:value-of select="//XSLPath"/>media/svg/feet_XSL.svg</xsl:attribute>      </embed>
</xsl:for-each>

I need to change the name of the embed (SVGDiagram) to unique identifiers e.g. append a 1,2 etc. so the embed name would be SVGDiagram1, SVGDiagram2 etc.

I believe this may be possible through using the tag <xsl:variable within the attribute tag, or by using some script within CDATA sections. Can anyone shed any light?

Cheers

0
Comment
Question by:paulsidebottom
  • 3
  • 3
7 Comments
 
LVL 2

Expert Comment

by:wellilein
ID: 9633209
I think

<xsl:variable name="enumerate" select="0"></xsl:variable>
<xsl:for-each select="Diagram">
      <xsl:variable name="enumerate" select="$enumerate+1"></xsl:variable>
     <embed height="163.8"  width="172.20">
     <xsl:attribute name="id">SVGDiagram<xsl:copy-of select="$enumerate"></xsl:copy-of></xsl:attribute>
     </embed>
</xsl:for-each>

should work, but XML-Spy has trouble with redefining the variable enumerate. I already encountered the problem once and I think the solution was to take a different transformer.
0
 

Expert Comment

by:berni_brown
ID: 9633227
Hi,

How are you intending to access the XSL file, which XML processor are you using?

0
 
LVL 2

Expert Comment

by:wellilein
ID: 9633269
If the only purpose is to distinguish Names, you might try position()

<xsl:for-each select="Diagram">
<xsl:variable name="enumerate" select="position()"/>
     <embed height="163.8"  width="172.20">
     <xsl:attribute name="id">SVGDiagram<xsl:copy-of select="$enumerate"></xsl:copy-of></xsl:attribute>
     </embed>
</xsl:for-each>

This also works in XML Spy.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:paulsidebottom
ID: 9633452
Thanks but...my XSL translator (IE5.5) is having problems with the redefiniton of enumerate as well.

Problem is, due to the way the XML is structured (diagram elements are grouped under a parent ), all elements named diagram return a position of 1, hence I can't use <xsl:value-of select="position()">

Thanks for your input so far though!

0
 
LVL 1

Author Comment

by:paulsidebottom
ID: 9633624
Sorry forgot to mention I am using MSXML3.0 XML parser
0
 
LVL 2

Accepted Solution

by:
wellilein earned 225 total points
ID: 9633722
Ok, try using the position of another element, maybe the parent element.

      <xsl:for-each select="Parent">
            <xsl:variable name="enumerate" select="position()"></xsl:variable>
            <xsl:for-each select="Diagram">
                 <embed height="163.8"  width="172.20">
                 <xsl:attribute name="id">SVGDiagram<xsl:copy-of select="$enumerate"></xsl:copy-of></xsl:attribute>
                 </embed>
           </xsl:for-each>
      </xsl:for-each>

will work fine if Parent has a position and has only one diagram. (If the parent contains more than one diagram, you could perhaps define two variables and concatenate them.)
0
 
LVL 1

Author Comment

by:paulsidebottom
ID: 9634077
Pure Genius! worked perfectly. Thanks a lot
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 105
How to insert gas or chemical names in SQL server. For e.g. CO2 to CO₂. 5 77
Removing line numbers from left column in config file 7 61
printf performancy 11 70
A short article about a problem I had getting the GPS LocationListener working.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question