XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
jason gohSubject: xsl node number
Author: jason goh
Date: 27 May 2008 07:26 AM
Hi All,

I am a bit of a noob to Xpath & XSL and was wondering whether any of you could help me with a problem I've got. My xml structure looks like:

<nodeList>
<node id="c6"/>
<node id="c8"/>
<node id="c14"/>
</nodeList>
<linkList>
<link id="1" source="c6" target="c8">
<link id="2" source="c8" target="c14">
</linkList>

What I'd like to do is replace linkList/link/@source with the corresponding node position (e.g. 1,2,3) from nodeList.

i.e. something like
<xsl:for-each select="linkList/link">
<link id="1">
<xsl:attribute name="source">
<xsl:value-of select="../../linkList/link[@id=@source]"/>
</xsl:attribute>
</link>
</xsl:for-each)

The above value-of gets me to the node I require but to get the node number e.g. c6 -> 1, c8 -> 2 etc.
Also @source seems to need to have the full path which then ignores the for-each (always picks the first element).

Any help would be much appreciated!
Thanks,
Jason

Postnext
jason gohSubject: xsl node number
Author: jason goh
Date: 27 May 2008 08:54 AM
Found a couple of posts that pointed me in the right direction and managed to solve the problem:

to solve the 'losing' the current value of @source, stored it in a variable.
and to get the current node number, counted the preceding siblings + 1...

<xsl:variable name="sauce"><xsl:value-of select="@source"/></xsl:variable> <xsl:attribute name="From">
<xsl:value-of select="count(../../nodeList/node[@id=$sauce]/preceding- sibling::*)+1"/>
</xsl:attribute>

Posttop
Tony LavinioSubject: xsl node number
Author: Tony Lavinio
Date: 27 May 2008 08:54 AM
If you are a Stylus Studio user, could you please let us know your
product version number, so we may better help you?

If not, or for general XSLT questions not related to Stylus Studio
products, please see the xsllist run by Mulberry Technologies.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.