Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Refer to an element using a variable [Thread Next] Re: Refer to an element using a variableTo: NULL Date: 4/9/2005 10:24:00 AM Following is a small example illustrating the idea..
XML file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<test>
<nameList>
<name1>Mukul</name1>
<name2>Nikhil</name2>
</nameList>
<phoneList>
<phone1>9899123456</phone1>
<phone2>3099777111</phone2>
</phoneList>
</test>
XSLT file:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="/test">
<xsl:apply-templates select="nameList" />
</xsl:template>
<xsl:template match="nameList">
<xsl:for-each select="*">
<xsl:variable name="pos" select="position()" />
<xsl:value-of select="." /> : <xsl:value-of
select="../following-sibling::phoneList[1]/*[$pos]" /><xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The output is -
Mukul : 9899123456
Nikhil : 3099777111
Regards,
Mukul
"John Smith" wrote:
> Hi,
>
> What I REALLY want to do is following:
>
> With this xml:
>
> <nameList>
> <name1/>
> <name2/>
> </nameList>
>
> <phoneList>
> <phone1/>
> <phone2/>
> </phoneList>
>
> When I am processing <name1>, I would like to get <phone1> and when <name2>,
> get <phone2>.
>
> I tried position() but it doesn't seem to work.
>
> TIA.
>
> JS
>
> "John Smith" <Jsmith@e...> wrote in message
> news:42544573$0$34296$a32e20b9@n......
> > Hi,
> >
> > Instead of refereeing an element using a number, such as
> >
> > myElement[2]
> >
> > Can I refer it using a variable such as
> >
> > myElement[$index] ?
> >
> > Thanks for help.
> >
> > JS
> >
> >
>
>
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
