Closed Bug 590862 Opened 14 years ago Closed 14 years ago

the xpath expression "count(preceding-sibling::use)" doesn't work

Categories

(Core :: XSLT, defect)

x86
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: cyrilapan, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows NT 6.1; rv:2.0b4) Gecko/20100818 Firefox/4.0b4
Build Identifier: Mozilla/5.0 (Windows NT 6.1; rv:2.0b4) Gecko/20100818 Firefox/4.0b4

Say you have this XML tree:

<?xml-stylesheet type="text/xsl" href="test.xsl" ?>
<svg>
<use id="a"/>
<use id="b"/>
</svg>

Then you want to apply this test.xsl:

<xsl:stylesheet>
<xsl:template match="/svg">
<xsl:for-each select="*">
<xsl:value-of select="count(preceding-sibling::use)"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

The output would be "00" instead of "01".
There's a workaround, replace the xpath expression by count(preceding-sibling::*[name()='use']) and it will work as expected (with an output of "01"). But both expression should be equivalent and return the same result.

Reproducible: Always

Steps to Reproduce:
1.Create an xml file with the content given above
2.Create an xsl file with the other content above
3.Open the xml in Firefox
Actual Results:  
Output is "00"

Expected Results:  
Output should be "01"
I'm assuming your markup actually looks like:

<svg xmlns="http://www.w3.org/2000/svg">
<use id="a"/>
<use id="b"/>
</svg>

Is this correct?

If so, you need to use

count(preceding-sibling::svg:use)

in a context where the 'svg' prefix has been mapped to the "http://www.w3.org/2000/svg" namespace. For example by doing

<xsl:stylesheet xmlns:svg="http://www.w3.org/2000/svg">

Or you can use the name() hack, which is specced to work just fine. It's just somewhat slower to execute.
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → INVALID
I'm confused about this. Thanks a lot Jonas to have taken a look on this. I think I'll look at my code twice before submitting a bug now...It seems that Opera xslt parser is more permissive in some areas.
You need to log in before you can comment on or make changes to this bug.