[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Charles Flanders wrote:
Well position() depends on how you process the 'CONDITION' elements for instance if you have
<xsl:template match="Document">
<xsl:apply-templates select="CONDITION"/>
<xsl:template>
then in your template matching CONDITION for the first such element in your sample document position() will return 1, for the second it will return 2. So you could store
<xsl:variable name="pos" select="position()"/>
Your variable CurrentCond does not make much sense to me as you are trying to access a CONDITION child element inside the template for CONDITION elements and in your XML sample your CONDITION elements do not have any children of the same name.
If you don't want to depend on the position() function and the way nodes are processed to count nodes then look into the count function or look into xsl:number e.g.
<xsl:variable name="pos">
<xsl:number/>
<xsl:variable>
--
Re: [xsl] Capturing position as a number
Subject: Re: [xsl] Capturing position as a number From: Martin Honnen <Martin.Honnen@xxxxxx> Date: Wed, 18 Mar 2009 19:24:12 +0100 |
Charles Flanders wrote:
I need to capture an elements position as an integer to a variable so I can use that number in capture the text from another element that shares the same position number in another part of the tree.
My XML looks something like this:
<Document>
<CONDITION>
<HYPERPROC linkend="M16-66A.-HP1">Webbing straps removed</HYPERPROC>
</CONDITION>
<CONDITION>
<HYPERPROC linkend="M16-66A.-HP2">Remote Terminal Unit Removed</HYPERPROC></CONDITION>
</Document>
My template:
<xsl:template match="CONDITION">
<xsl:variable name="CurrentCond"><xsl:value-of select="CONDITION[position()]"/></xsl:variable>
Well position() depends on how you process the 'CONDITION' elements for instance if you have
<xsl:template match="Document">
<xsl:apply-templates select="CONDITION"/>
<xsl:template>
then in your template matching CONDITION for the first such element in your sample document position() will return 1, for the second it will return 2. So you could store
<xsl:variable name="pos" select="position()"/>
Your variable CurrentCond does not make much sense to me as you are trying to access a CONDITION child element inside the template for CONDITION elements and in your XML sample your CONDITION elements do not have any children of the same name.
If you don't want to depend on the position() function and the way nodes are processed to count nodes then look into the count function or look into xsl:number e.g.
<xsl:variable name="pos">
<xsl:number/>
<xsl:variable>
--
Martin Honnen http://JavaScript.FAQTs.com/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Capturing position as a n, Geert Josten | Thread | [xsl] Convet SGML data to XML forma, Happy Name |
RE: [xsl] Capturing position as a n, Geert Josten | Date | [xsl] Convet SGML data to XML forma, Happy Name |
Month |
Keywords