[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: document() and position()
Dirk, >But now I need to know the number of the actual file I >read in the template I call. I tried something like this: > ><xsl:apply-templates select="document(/page/folder)/news[@show = 'true']"> > <xsl:with-param name="index"><xsl:value-of select="position()" >/></xsl:with-param> ></xsl:apply-templates> > >But the index parameter is allways '1'. How can I get >the position? Or is there any other way to get the >number of the actual xml file? Within your xsl:apply-templates above, you set the value of the parameter $index to the value of the position() of the current node within the current node list. The xsl:apply-templates doesn't do anything to change the value of the current node, so if this is in a template like: <xsl:template match="/"> <xsl:apply-templates select="document(/page/folder)/news[@show = 'true']"> <xsl:with-param name="index"> <xsl:value-of select="position()" /> </xsl:with-param> </xsl:apply-templates> </xsl:template> then the current node when setting the parameter value is still the root node of the input document. As there is only one of these, the value is always 1. I'm not exactly sure which position you are interested in: the index of the file within the files that you're actually retrieving (i.e. only those for whom @show = 'true') or the index of the file within all the files that you could have retrieved. If you want to find the position of the 'news' element amongst the other 'news' elements that you're actually retrieving, you want to use the position() function when the current node is the 'news' element you're interested in and the current node list is the list of the 'news' elements that you've retrieved. This is the situation within the 'news'-matching templates that are applied using the xsl:apply-templates you've specified above, so try something like: <xsl:template match="/"> <xsl:apply-templates select="document(/page/folder)/news[@show = 'true']" /> </xsl:template> <xsl:template match="news"> <xsl:variable name="index" select="position()" /> News item <xsl:value-of select="$index" /> ... </xsl:template> If you want to find the position of the 'news' element amongst the 'news' elements that you *could* have retrieved, you want to use the position() function when the current node is the 'news' element you're interested in and the current node list is the list of all the 'news' elements, whether @show='true' or not. In that case, try something like: <xsl:template match="/"> <xsl:apply-templates select="document(/page/folder)/news" /> </xsl:template> <xsl:template match="news"> <xsl:variable name="index" select="position()" /> <xsl:if test="@show = 'true'"> News item <xsl:value-of select="$index" /> ... </xsl:if> </xsl:template> I hope that this helps, Jeni Dr Jeni Tennison Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@xxxxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|