[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: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 27 Feb 2002 14:44:01 +0000
xsl param position
Hi Gurvinder,

> Yes the structure is always like this (i.e data and display nodes
> are always siblings) but the xpath can change (different names of
> tags..).. we want to keep it at one place so that if we want to
> change something we have to change only at one place..
>
> For example, are the display nodes and associated data nodes
> always siblings of each other, nested under some other node? Very Correct..

In that case, there are a couple of other models that you could try.

First, you could pass the set of nodes that are the parents of the
data and display nodes in as a parameter, with two separate
parameters, $dataName and $displayName holding the names of the
elements that you want to sort. The template would be:

<xsl:template name="lookup">
  <xsl:param name="name" />
  <xsl:param name="nodes" select="/.." />
  <xsl:param name="dataName" select="'data'" />
  <xsl:param name="displayName" select="'display'" />
  <select name="{$name}">
    <xsl:for-each select="$nodes">
      <xsl:sort select="*[name() = $displayName]" />
      <xsl:variable name="data" select="*[name() = $dataName]" />
      <option id="{$data}" value="{$data}">
        <xsl:value-of select="concat($data, '-',
                                     *[name() = $displayName]" />
      </option>
    </xsl:for-each>
  </select>
</xsl:template>

You could call this with:

  <xsl:call-template name="lookup">
    <xsl:with-param name="name" select="'test'" />
    <xsl:with-param name="nodes" select="/test/Level2" />
  </xsl:call-template>

[Here assuming that the elements holding the data are called 'data'
and the elements holding the display are called 'display'.]
  
A second option is to pass in the displayNodes as a parameter, and a
string giving the name of the element that holds the data. That's even
simpler:

<xsl:template name="lookup">
  <xsl:param name="name" />
  <xsl:param name="displayNodes" select="/.." />
  <xsl:param name="dataName" select="'data'" />
  <select name="{$name}">
    <xsl:for-each select="$displayNodes">
      <xsl:sort select="." />
      <xsl:variable name="data" select="../*[name() = $dataName]" />
      <option id="{$data}" value="{$data}">
        <xsl:value-of select="concat($data, '-', .)" />
      </option>
    </xsl:for-each>
  </select>
</xsl:template>

You could call this with:

  <xsl:call-template name="lookup">
    <xsl:with-param name="name" select="'test'" />
    <xsl:with-param name="displayNodes" select="/test/Level2/display" />
  </xsl:call-template>

[Again assuming that the element holding the data are called 'data'.]

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.