GNOME Bugzilla – Bug 53769
position() returns 0 in global context
Last modified: 2009-08-15 18:40:50 UTC
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:variable name="pos" select="position()"/> <xsl:template match="/"> <pos><xsl:value-of select="$pos"/></pos> </xsl:template> </xsl:stylesheet> ...The output I get is <pos>0</pos>, which is strictly in contravention of the XPath and XSLT specifications, which say that the current node position must always be a nonzero positive integer, and that the context for evaluation of global expressions is a node-set containing a single node which is the root of the source document. (I can point out the relevant parts of the specification if you want.) Tested in version 0.8.0.
Sure it's a bug: 11.4 Top-level Variables and Parameters "At the top-level, the expression or template specifying the variable value is evaluated with the same context as that used to process the root node of the source document: the current node is the root node of the source document and the current node list is a list containing just the root node of the source document." Following fixes it: ------------------- *** variables.c 2001/04/29 09:52:50 1.27 --- variables.c 2001/04/29 16:17:00 *************** *** 363,368 **** --- 363,370 ---- "Evaluating global variables\n"); #endif ctxt->node = (xmlNodePtr) ctxt->document->doc; + ctxt->xpathCtxt->contextSize = 1; + ctxt->xpathCtxt->proximityPosition = 1; style = ctxt->style; while (style != NULL) { elem = style->variables; -------------------------- orchis:~/XSLT/tests/general -> xsltproc bug-17-.xsl ../docs/bug-17-.xml <?xml version="1.0"?> <pos>1</pos> orchis:~/XSLT/tests/general -> thanks for the report, Daniel
shipped in 0.9.0 Daniel