Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 3rd, 2006, 06:10 PM
Registered User
 
Join Date: Jan 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Even/odd rows: difference between Firefox and IE

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?

[u]foo.xml</u>
Code:
<?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>
[u]foo.xls</u>
Code:
<?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>
 
Old January 3rd, 2006, 08:40 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old January 9th, 2006, 04:12 PM
Registered User
 
Join Date: Jan 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
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???

 
Old January 9th, 2006, 04:25 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
IF statements with even or odd numbers sanderson Beginning VB 6 1 July 15th, 2008 02:19 PM
Odd InputBox error Archdeacon VBScript 3 June 15th, 2008 10:50 PM
Odd form behaviour jeremy1048 Access 0 April 25th, 2008 08:13 AM
Rather odd web-project oldmainframehack Javascript How-To 0 August 8th, 2007 09:03 AM
Need help with XSLFO - even/odd pages nyctechwriter XSLT 0 August 23rd, 2006 11:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.