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




8 years ago
8 years ago


(Reporter: cyrilapan, Unassigned)


Firefox Tracking Flags

(Not tracked)




8 years ago
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" ?>
<use id="a"/>
<use id="b"/>

Then you want to apply this test.xsl:

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

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="">
<use id="a"/>
<use id="b"/>

Is this correct?

If so, you need to use


in a context where the 'svg' prefix has been mapped to the "" namespace. For example by doing

<xsl:stylesheet xmlns:svg="">

Or you can use the name() hack, which is specced to work just fine. It's just somewhat slower to execute.
Last Resolved: 8 years ago
Resolution: --- → INVALID

Comment 2

8 years ago
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.