Solved

Using variables within XSL Output

Posted on 2003-10-28
7
238 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Report events not being triggered 8 100
linearIn  challenge 23 65
ClickOnce Install - Shortcut Question 3 58
oracle query help 18 78
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now