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: Gurvinder Singh <GurvinderS at amdocs dot com>
- To: "'Jeni Tennison'" <jeni at jenitennison dot com>
- Cc: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 27 Feb 2002 17:03:39 +0200
- Subject: RE: [xsl] getting the node position in source xml in a variable
- Reply-to: xsl-list at lists dot mulberrytech dot com
Thanks Very much...
I have one more query... you said that i am not passing the result tree
fragment
what does it mean...
i thought when i select nodes and pass it as parameter is is passing result
tree fragment
Thanks & Regards
Gurvinder
Amdocs Limited , Cyprus
-----Original Message-----
From: Jeni Tennison [mailto:jeni@jenitennison.com]
Sent: Wednesday, February 27, 2002 4:44
To: Gurvinder Singh
Cc: 'xsl-list@lists.mulberrytech.com'
Subject: Re: [xsl] getting the node position in source xml in a variable
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