| Author |
Firefox XSLT position()
|
|
| David 2005-06-03, 11:31 pm |
| 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
| |
| David 2005-06-03, 11:31 pm |
| Ok, I find something that output what I expected.
Hope it will work on IE6 too.
<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 select="AAA"/>
</body>
</html>
</xsl:template>
<xsl:template match="AAA">
<xsl:apply-templates select="BBB" />
</xsl:template>
<xsl:template match="BBB">
<p>(<xsl:value-of select="position()" /> )
<xsl:value-of select="." />
</p>
</xsl:template>
</xsl:stylesheet>
| |
| Lucky 2005-06-03, 11:31 pm |
| 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;
| |
| Martin Honnen 2005-06-03, 11:31 pm |
|
David wrote:
> 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>
There are white space text nodes between the <BBB> elements which
MSXML/IE ignores thus with Mozilla if you use
<xsl:apply-templates />
the current nodeset contains both element nodes as well as text nodes
while MSXML/IE has only elements in the nodeset.
--
Martin Honnen
http://JavaScript.FAQTs.com/
| |
| David 2005-06-03, 11:31 pm |
| Martin Honnen a écrit :
> There are white space text nodes between the <BBB> elements which
> MSXML/IE ignores thus with Mozilla if you use
> <xsl:apply-templates />
> the current nodeset contains both element nodes as well as text nodes
> while MSXML/IE has only elements in the nodeset.
>
Ok thanks.
So either I put my XML on one line something like :
<AAA><BBB>a</BBB><BBB>b</BBB><BBB>c</BBB></AAA>
or I use <xsl:strip-space elements="*"/> in the beggining
of my XSL.
| |
| Martin Honnen 2005-06-03, 11:31 pm |
|
David wrote:
> So either I put my XML on one line something like :
> <AAA><BBB>a</BBB><BBB>b</BBB><BBB>c</BBB></AAA>
If you are only interested in child elements then as you have already
found out you can use
<xsl:apply-templates select="*" />
instead of
<xsl:apply-templates />
that way both XSLT processors process the same nodeset and position()
will yield the same results.
--
Martin Honnen
http://JavaScript.FAQTs.com/
|
|
|
|
| Copyright 2003 - 2009 forum4designers.com Software forum Computer Hardware reviews |