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

RE: getting the node position in source xml in a varia

Subject: RE: getting the node position in source xml in a variable
From: Gurvinder Singh <GurvinderS@xxxxxxxxxx>
Date: Wed, 27 Feb 2002 15:45:08 +0200
gurvinder singh
Thanks 
But still didnt work
It always takes the first node from the second nodelist...

If i print the value of $num variable it always prints '1'
If i try to print the count(preceding-sibling::*) + 1 again it prints always
1

Thanks & Regards

Gurvinder
Amdocs Limited , Cyprus


-----Original Message-----
From: Jeni Tennison [mailto:jeni@xxxxxxxxxxxxxxxx]
Sent: Wednesday, February 27, 2002 3:01
To: Gurvinder Singh
Cc: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Subject: Re:  getting the node position in source xml in a variable


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


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.