After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 53769 - position() returns 0 in global context
position() returns 0 in global context
Status: VERIFIED FIXED
Product: libxslt
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Daniel Veillard
Daniel Veillard
Depends on:
Blocks:
 
 
Reported: 2001-04-27 16:14 UTC by Dan Egnor
Modified: 2009-08-15 18:40 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Dan Egnor 2001-04-27 16:14:55 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.
Comment 1 Daniel Veillard 2001-04-29 16:20:51 UTC
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
Comment 2 Daniel Veillard 2001-05-04 10:40:21 UTC
shipped in 0.9.0

Daniel