This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: getting the node position in source xml in a variable
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: Gurvinder Singh <GurvinderS at amdocs dot com>
- Cc: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 27 Feb 2002 13:01:26 +0000
- Subject: Re: [xsl] getting the node position in source xml in a variable
- Organization: Jeni Tennison Consulting Ltd
- References: <D1713728C4550440A0E4A0816702E75C02E375C5@cypmail1srv.corp.amdocs.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Gurvinder,
> I dont think that when i convert using msxml:node-set i get a single
> root node...
Then you're not passing in result tree fragments, which means that you
don't need to use the msxsl:node-set() function at all :)
Try:
<xsl:template name="lookup">
<xsl:param name="name"/>
<xsl:param name="datanodes"/>
<xsl:param name="displaynodes"/>
<select name="{$name}">
<xsl:for-each select="$displaynodes">
<xsl:sort select="." />
<xsl:variable name="num"
select="count(preceding-sibling::*) + 1"/>
<xsl:variable name="data"
select="$datanodes[$num]" />
<option id="{$data}" value="{$data}">
<xsl:value-of select="$data"/>-<xsl:value-of select="."/>
</option>
</xsl:for-each>
</select>
</xsl:template>
Note how the $num variable is being set - to the number of preceding
siblings that the display node has, plus one. Thus $num is based on
the position of the display node within the original source rather
than on its position within the sorted list.
You could instead use the xsl:number element:
<xsl:template name="lookup">
<xsl:param name="name"/>
<xsl:param name="datanodes"/>
<xsl:param name="displaynodes"/>
<select name="{$name}">
<xsl:for-each select="$displaynodes">
<xsl:sort select="." />
<xsl:variable name="num">
<xsl:number />
</xsl:variable>
<xsl:variable name="data"
select="$datanodes[$num]" />
<option id="{$data}" value="{$data}">
<xsl:value-of select="$data"/>-<xsl:value-of select="."/>
</option>
</xsl:for-each>
</select>
</xsl:template>
Though that won't give you the same number unless all the display
nodes are of the same type (i.e. they're elements with the same name).
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list