|
Subject:
|
Even/odd rows: difference between Firefox and IE
|
|
Posted By:
|
isme
|
Post Date:
|
1/3/2006 5:10:07 PM
|
I have noticed an annoying difference between Firefox 1.0.7 and IE 6.0 with regards to the XPath position() function.
The return value of the position() function is displayed in the first column that is generated by the xml/xsl. When rendering the file foo.xml (see below) in IE this column displays 1 in row 1 and 2 in row 2 whereas in Firefox it contains 2 in row 1 and 4 in row 2. Am I doing something silly or is this a known Firefox bug?
foo.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="foo.xsl"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
</cd>
</catalog>
foo.xls
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="catalog">
<table border="0" cellpadding="2" cellspacing="2">
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="cd">
<tr>
<td><xsl:value-of select="position()"/></td>
<xsl:for-each select="descendant::*">
<td><xsl:value-of select="."/></td>
</xsl:for-each>
</tr>
</xsl:template>
</xsl:stylesheet>
|
|
Reply By:
|
mhkay
|
Reply Date:
|
1/3/2006 7:40:30 PM
|
No, it's a known IE bug. MSXML3/4 strips all the whitespace text nodes before XSLT processing even begins. No other XSLT processor does this; though the spec arguably permits it because it doesn't dictate what happens before XSLT processing starts. If you want other XSLT processors to behave like this, do <xsl:strip-space elements="*"/>.
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
Reply By:
|
isme
|
Reply Date:
|
1/9/2006 3:12:43 PM
|
quote: Originally posted by mhkay
No, it's a known IE bug. MSXML3/4 strips all the whitespace text nodes before XSLT processing even begins. No other XSLT processor does this; though the spec arguably permits it because it doesn't dictate what happens before XSLT processing starts. If you want other XSLT processors to behave like this, do <xsl:strip-space elements="*"/>.
Thanks Michael, using the <xsl:strip-space elements="*"/> had indeed the desired effect. However, I'm at a loss to explain why. Where in my example xml file are whitespace text nodes???
|
|
Reply By:
|
mhkay
|
Reply Date:
|
1/9/2006 3:25:59 PM
|
For example, there is one after the opening <cd> tag and before the opening <title> tag; there is another between the <title> end tag and the <artist> start tag.
In XML like yours, these text nodes are usually of no significance. But this kind of XML is a special case: when XML is used for its original purposes of handling markup in text, spaces in the document content have the same significance as any other character.
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|