Subject: Re: position() problem with // axis + parent numbering problem From: Warren Hedley <w.hedley@xxxxxxxxxxxxxx> Date: Tue, 18 Apr 2000 21:50:58 +1200 |
Kay Michael wrote: > > Can you tell us *exactly* what you wrote? Here's the XML, XSL and output (the <temp> elements are just there to add depth to the tree - making it look a bit more like my real problem). XML --- <?xml version="1.0"?> <!DOCTYPE document> <document> <children> <temp> <text>P1</text> <children> <temp> <text>P2</text> <text>P3</text> <text>P4</text> <text>P5</text> </temp> </children> </temp> </children> </document> --- XSL --- <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text" /> <xsl:template match="/"> <xsl:for-each select="//text[1]"> <xsl:text>First node (</xsl:text> <xsl:value-of select="position()" /> <xsl:text>) = `</xsl:text> <xsl:value-of select="." /> <xsl:text>' </xsl:text> </xsl:for-each> <xsl:for-each select="//text[not(position() = 1)]"> <xsl:text>Text (</xsl:text> <xsl:value-of select="position()" /> <xsl:text>) = `</xsl:text> <xsl:value-of select="." /> <xsl:text>' </xsl:text> </xsl:for-each> </xsl:template> </xsl:stylesheet> --- OUTPUT --- First node (1) = `P1' First node (2) = `P2' Text (1) = `P3' Text (2) = `P4' Text (3) = `P5' --- Note that the first template has been called twice, and a position() call inside the template returns the correct position in the context list, yet the result appears to conflict with the predicate [1]. In fact they are mutually exclusive (whooops), just not what I was expecting. Any ideas on how I should be phrasing the [not(position() = 1)] predicate? At the moment I'm getting by checking the result of <xsl:number> inside the called template. > I think the <xsl:for-each> here is redundant. The <xsl:number> will give you > the number of the first ancestor that matches the count pattern. You're right - I'm sure I tried that! Thanks. -- Warren Hedley Department of Engineering Science Auckland University New Zealand XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: position() problem with // axis, David Carlisle | Thread | Re: position() problem with // axis, David Carlisle |
Variable Scope and xsl:if, Omar López Ruiz | Date | Re: Variable Scope and xsl:if, David Carlisle |
Month |