[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Capturing position as a number

Subject: Re: Capturing position as a number
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Wed, 18 Mar 2009 19:24:12 +0100
Re:  Capturing position as a number
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.