Solved

Using variables within XSL Output

Posted on 2003-10-28
7
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Make the most of your online learning experience.
Introduction to Processes
Starting up a Project

695 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