[xml] bug with variables and predicates



Hi,

 

In our app, we use libxml2 and we connect XPath variables to our proprietary script language and its variables. I have recently noticed a possible bug with it. To replicate the issue, I have created an xslt. Handling of variables is a bit grey zone for me, but I think there has to be a bug somewhere in libxml2.

 

First the xslt (note the different bracketing around $array):

<?xml version="1.0"?>

 

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:exsl="http://exslt.org/common">

 

<xsl:variable name="array_orig">

              <item>1234</item>

              <item>12</item>

              <item>123</item>

              <item>1</item>

</xsl:variable>

 

<xsl:variable name="array" select="exsl:node-set($array_orig)/item"/>

 

<xsl:template match="/">

              <data>

                             <cnt><xsl:value-of select="count($array)"/></cnt>

                             <l1><xsl:value-of select="string-length($array[1])"/></l1>

                             <l2><xsl:value-of select="string-length(($array)[1])"/></l2>

                             <l3><xsl:value-of select="string-length($array[2])"/></l3>

                             <l4><xsl:value-of select="string-length(($array)[2])"/></l4>

                             <test1>

                                           <xsl:for-each select="$array[string-length($array[1])]">

                                                         <xsl:element name="{name()}">

                                                                       <xsl:value-of select="."/>

                                                         </xsl:element>

                                           </xsl:for-each>

                             </test1>

                             <test2>

                                           <xsl:for-each select="$array[string-length(($array)[1])]">

                                                         <xsl:element name="{name()}">

                                                                       <xsl:value-of select="."/>

                                                         </xsl:element>

                                           </xsl:for-each>

                             </test2>

                             <test3>

                                           <xsl:for-each select="$array[string-length($array[2])]">

                                                         <xsl:element name="{name()}">

                                                                       <xsl:value-of select="."/>

                                                         </xsl:element>

                                           </xsl:for-each>

                             </test3>

                             <test4>

                                           <xsl:for-each select="$array[string-length(($array)[2])]">

                                                         <xsl:element name="{name()}">

                                                                       <xsl:value-of select="."/>

                                                         </xsl:element>

                                           </xsl:for-each>

                             </test4>

              </data>

</xsl:template>

 

</xsl:stylesheet>

 

Xslproc produces (xml file is not important, you can use any, I have added whitespace):

<?xml version="1.0"?>

<data xmlns:exsl="http://exslt.org/common">

<cnt>4</cnt>

<l1>4</l1>

<l2>4</l2>

<l3>2</l3>

<l4>2</l4>

<test1/>

<test2>

<item>1</item>

</test2>

<test3/>

<test4/>

</data>

 

I would expect to have “item” element also in test1, test3 and test4. The string lengths are 4 or 2 (see l1, l2, l3, l4). There are four elements in $array, see “cnt” element. I have tried it with ms xslt and the “item” elements are there as I would expect.

 

Vojtech



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