Subject: Re: [xsl] Select nodes with equal position From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> Date: Sun, 3 Apr 2005 07:40:01 +1000 |
This transformation shows how to avoid evaluating the position in an xsl:variable: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:template match="/"> <xsl:for-each select="/*/*/entry"> <xsl:value-of select= "/*/colspec[position() = count(current()/preceding-sibling::entry)+1]/@colname"/> <xsl:text>
</xsl:text> </xsl:for-each> </xsl:template> </xsl:stylesheet> When performed on the original xml source document: <table> <colspec colname="c1"/> <colspec colname="c2"/> <colspec colname="c3"/> <row> <entry colname="c1">r1_1</entry> <entry colname="c2">r1_2</entry> <entry colname="c3">r1_2</entry> </row> </table> the correct result is produced: c1 c2 c3 Cheers, Dimitre Novatchev On Apr 3, 2005 4:28 AM, Norbert Heidbrink <nh@xxxxxxxx> wrote: > Hallo everyone, > > depending on the postion() of a certain node I would like to select > another node with the same position. > It works if I invent a variable. > But I wonder if there is a way to do it without the use of a variable? > > XML: > > <table> > <colspec colname="c1"/> > <colspec colname="c2"/> > <colspec colname="c3"/> > <row> > <entry colname="c1">r1_1</entry> > <entry colname="c2">r1_2</entry> > <entry colname="c3">r1_2</entry> > </row> > </table> > > XSL: > <xsl:template match="entry"> > <xsl:variable name="mypos"> > <xsl:value-of select="position()"/> > </xsl:variable> > <xsl:value-of select="../../colspec[position() = $mypos]/@colname"/> > </xsl:template> > > Best regards and thanks for your comments, > Norbert Heidbrink
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Select nodes with equal p, Michael Kay | Thread | RE: [xsl] Select nodes with equal p, Michael Kay |
Re: [xsl] Select nodes with equal p, David Carlisle | Date | Re: [xsl] Schema declarations showi, David Carlisle |
Month |