Re: Firefox XSLT position()

Lucky <[email protected]>
Newsgroups gmane.comp.mozilla.devel.layout.xslt
Organization Cox Communications
Message-ID <YKYee.18528$Um.6490@lakeread08>
David wrote:
> Hi all,
> As a newby, I don't understand the position() in Firefox.
> Here my XML sample.
> 
> <?xml version="1.0" encoding="iso-8859-1"?>
> <?xml-stylesheet type="text/xsl" href="aaa.xsl"?>
> <AAA>
>   <BBB>a</BBB>
>   <BBB>b</BBB>
>   <BBB>c</BBB>
> </AAA>
> 
> 
> Here my two XSLT tests
> 1.
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
> version="1.0">
> 
> <xsl:template match="/">
>   <html>
>     <body>
>       <p>(<xsl:value-of select="position()" />)</p>
>       <xsl:apply-templates/>
>     </body>
>   </html>
> </xsl:template>
> 
> <xsl:template match="BBB">
>       <p>(<xsl:value-of select="position()" />)
>       <xsl:value-of select="." />
>       </p>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> 
> 2.
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
> version="1.0">
> 
> <xsl:template match="AAA">
>   <html>
>     <body>
>       <p>(<xsl:value-of select="position()" />)</p>
>       <xsl:for-each select="BBB">
>       <p>
>         (<xsl:value-of select="position()"/>)
>         <xsl:value-of select="."/>
>       </p>
>       </xsl:for-each>
>     </body>
>   </html>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> What I expect is something like:
> 
> (1)
> 
> (1) a
> 
> (2) b
> 
> (3) c
> 
> For 1. I have :
> 
> (1)
> 
> (2) a
> 
> (4) b
> 
> (6) c
> 
> For 2.  I have:
> 
> (2)
> 
> (1) a
> 
> (2) b
> 
> (3) c
> 
> Is there something wrong about position() on Firefox
> or I do something wrong ?
> (I have test a little on IE and it seems to work as expected)
> 
> Thanks for you light.
> David
this does seem a bit odd, it seems to be something with the way Moz 
calculates in the #text areas, or whitespacing of node indentions;

here is a modified version #1 you had:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">
   <xsl:template match="/">
     <html>
       <body>
         <p>(<xsl:value-of select="position()"/>)</p>
         <xsl:apply-templates/>
       </body>
     </html>
   </xsl:template>
   <xsl:template match="BBB">
     <p>
       (<xsl:value-of select="position()"/>)
       [<xsl:value-of select="name()"/>]
       <xsl:value-of select="."/>
     </p>
   </xsl:template>
   <xsl:template match="text()">
     <p>
       (<xsl:value-of select="position()"/>)
       [#text] length="<xsl:value-of select="string-length(.)"/>"
     </p>
   </xsl:template>
</xsl:stylesheet>

prints out:
(1)

(1) [#text] length="3"

(2) [BBB] a

(3) [#text] length="3"

(4) [BBB] b

(5) [#text] length="3"

(6) [BBB] c

(7) [#text] length="1"

and your #3 version seems fine for both ie + moz;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.