[xslt] ?Bug/Mystery - Xpath last() function - libxml2 2.6.16 r2



Hi.

I have a strange (=incorrect+weird) behaviour when using libxml2 via xsltproc (and Perl XML:::LibXML/LibXSLT/AxKit)
It looks like using the 'last()' positional function corrupts a nodeset - or something more subtle
- which also affect a subsequent Xpath match!!
(and I don't think I'm doing anything stupid.)


I am running fedora core 2:
Using libxml 20616, libxslt 10112 and libexslt 810
xsltproc was compiled against libxml 20615, libxslt 10112 and libexslt 810
libxslt 10112 was compiled against libxml 20615
libexslt 810 was compiled against libxml 20615

libxml2 2.6.16 r2
libxslt 1.1.12 r2

I have just upgraded to these versions - when I noticed the error in the earlier versions I was using.

I get the same behaviour in Windows XP Pro SP2:
Using libxml 20617CVS2313, libxslt 10112CVS991 and libexslt 810CVS991
xsltproc was compiled against libxml 20617, libxslt 10112 and libexslt 810
libxslt 10112 was compiled against libxml 20617
libexslt 810 was compiled against libxml 20617

INTENT:
I am processing a file containing a sequence of <TABLE> elements.
I am processing just one <TABLE> - and providing navigation to the Previous and Next table,
looping round to the last on the 1st <TABLE>.


There are two strange parts to the behaviour.
1 - If I use 'last()' - rather than the positional index of the last element - in the code on line 48 below
I actually get the preceding-sibling::TABLE[2].
2 - (this is REALLY STRANGE) This also corrupts the following variable on line 49 to produce the SAME result


If I change line #48 below to use the $TOT index - then BOTH variables (TabPRev1 and TabPRev2) give the correct result!
when line #49 HASN'T CHANGED!!!


DETAILS:
The item of interest is the '(ID=...)' text.
The important XSLT template line is #48.

(I haven't changed the code that creates the '$NavPrev' = '<a href...>' link for the different
definitions of '$TabPrev[12] - so it WILL always output the correct '@href'.).


Using the following XSLT template on the 4th <TABLE> I get output:

     <td class="NavPrev">
            <a href="tab_0003.xml">Previous Table (ID=3)</a>
            <br/>
            <a href="tab_0003.xml">Previous TABLE (ID=2)</a>
            <br/>
            <a href="tab_0003.xml">Previous TABLE (ID=2)</a>
     </td>
which is wrong - they should all be the same.

XSLT template snippet:

40 <xsl:template match='TABLE' >
41 <xsl:param name='XIDX' select='/..'/>
42
43 <xsl:variable name='TOT' select='count($XIDX/TABLE)'/>
44 <xsl:variable name='XTAB' select='$XIDX/TABLE[ ID = current()/@ID]'/>
45 <xsl:variable name='TIDX' select='count($XTAB/preceding-sibling::TABLE)+1'/>
46
47 <xsl:variable name='TabPrev' select='( $XIDX/TABLE[$TIDX - 1] | $XIDX/TABLE[$TOT] )[1]'/>


48 <xsl:variable name='TabPrev1' select='( ($XTAB/preceding-sibling::TABLE[1]) | ($XIDX/TABLE[last()]) )[1]'/>

49 <xsl:variable name='TabPrev2' select='( $XTAB/preceding-sibling::TABLE[1] | $XIDX/TABLE[$TOT] )[1]'/>
<snip>...
54
55 <xsl:variable name='IDPrev' select='$TabPrev/@ID'/>
56 <xsl:variable name='IDPrev1' select='$TabPrev1/@ID'/>
57 <xsl:variable name='IDPrev2' select='$TabPrev1/@ID'/>
<snip>... 70 <td class='NavPrev'>
71 <a href='{$NavPrev}'>Previous Table (ID=<xsl:value-of select='$IDPrev'/>)</a>
72 <br />
73 <a href='{$NavPrev}'>Previous TABLE (ID=<xsl:value-of select='$IDPrev1'/>)</a>
74 <br />
75 <a href='{$NavPrev}'>Previous TABLE (ID=<xsl:value-of select='$IDPrev2'/>)</a>
76 </td>


If I change line 48 to (replacing 'last()' with '$TOT')

48 <xsl:variable name='TabPrev1' select='( ($XTAB/preceding-sibling::TABLE[1]) | ($XIDX/TABLE[$TOT]) )[1]'/>

I get output:

<td class="NavPrev">
<a href="tab_0003.xml">Previous Table (ID=3)</a>
<br/>
<a href="tab_0003.xml">Previous TABLE (ID=3)</a>
<br/>
<a href="tab_0003.xml">Previous TABLE (ID=3)</a>
</td>
which is now correct - but weird - as the 3rd '(ID=3)' has changed - but the XSLT code hasn't!!!!!!


I haven't looked at any libxml code as I haven't downloaded source and I'm not sure where to look (? xpath.c)
I haven't managed to find an FC2 version of the latest libxml2 yet - but don't see this listed in any bug fixes.



Mike



--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.7.4 - Release Date: 18/03/2005



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]