[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Select nodes with equal position
Hi David, I have a very basic question. Why this should not work - <xsl:template match="entry"> <xsl:value-of select="../../colspec[position()]/@colname"/> </xsl:template> My doubt came because.. If we use <xsl:value-of select="../../colspec[2]/@colname"/> i.e. if we use a static number as predicate of colspec , it expectedly gets(to my expectation!) the 2nd colspec child of table. But should'nt this <xsl:value-of select="../../colspec[position()]/@colname"/> do the same thing? If I run this program: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text" /> <xsl:template match="/"> <xsl:apply-templates select="table/row/entry" /> </xsl:template> <xsl:template match="entry"> <xsl:value-of select="../../colspec[position()]/@colname"/> </xsl:template> </xsl:stylesheet> With 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> The output is c1c1c1 . i.e. the instruction <xsl:value-of select="../../colspec[position()]/@colname"/> always picks element <colspec colname="c1"/> (i.e. 1st one).. This amazes me.. Can you please clarify the rationale behind the complex expression you wrote. And why simply [position()] should not work. Best regards, > If you really object to variables > > <xsl:value-of select="../../colspec[position() = count(current()/preceding-sibling::entry)+1]/@colname"/> > > but that's likely to be slower > > David > > ________________________________________________________________________ > This e-mail has been scanned for all viruses by Star. The > service is powered by MessageLabs. For more information on a proactive > anti-virus service working around the clock, around the globe, visit: > http://www.star.net.uk > ________________________________________________________________________
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|