RE: [xsl] Unanticipated Results from text()

Subject: RE: [xsl] Unanticipated Results from text()
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 23 Feb 2007 17:57:25 -0000
The Microsoft XML parser strips whitespace text nodes by default. (Indeed,
when running in IE from an xml-stylesheet PI it's impossible to prevent
this.) This runs against the spirit of the specs, and leads to this kind of
interoperability problem.

If you actually want the whitespace stripped, you can get this done in a
portable way by using <xsl:strip-space elements="*"/> in your stylesheet.

If you don't want the whitespace stripped, for example if you have

<p>My name is <first>Michael</first> <last>Kay</last></p>

in your source document, then you're hosed: you have to write Javascript
that politely asks Microsoft to give you all your XML, not just the bits it
thought you might find interesting.

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: Signature House [mailto:systems@xxxxxxxxxxxxxxxxxx] 
> Sent: 23 February 2007 17:35
> To: XSL List
> Subject: [xsl] Unanticipated Results from text()
> 
> Hi
> 
> I'm working on a project involving an XML import into the 
> FileMaker DB package. I'm using Internet Explorer to do 
> quickie proofing on my stylesheets before using them in FM 
> since FM is a bit of a kludge.
> 
> I got one bit working the way I wanted in IE, but got a 
> different result when I moved it into FM.
> 
> Using the IE STYLESHEET and XML INPUT 1 below, I got IE 
> RESULTS FROM BOTH INPUTS vs FM RESULTS FROM INPUT 1. The 
> "normalize-space(text())" picked up the B2 text in IE but 
> didn't in FM.
> 
> I ran about a dozen different versions of the XML input, 
> removing 1 or more line breaks from different places. IE 
> always picked up the B2 text; sometimes FM did, sometimes it 
> didn't (see at FM RESULTS FROM INPUT 2 for one where FM did work).
> 
> Empirically, if <BBB><CCC> were on the same line, IE & FM 
> returned the same results; if <BBB><CCC> were on separate 
> lines, the results were different.
> 
> I'm working on a PC running XP SP2, IE 6 SP2 and FM 8.03. FM 
> says they're using an Xerces-based XML parser and an 
> Xalan-based XSLT processor (Xerces-C 1.6.0, Xalan-C 1.3.0). 
> My stylesheets use the same XSLT, but for FM I have to remove 
> the HTML and add a bunch of required metadata. It's longish 
> so I didn't include it but I can if someone needs to see it. 
> The line breaks are the standard Windows hex 0D 0A pair.
> 
> Does anybody have any suggestions as to what is going on?
> - Is the placement of the B2 text valid XML?
> - Is this a difference between IE & Xalan?
> - What results should I expect - B2 or not B2? (Gee, I should 
> have used 2B as the sample!)
> 
> Thanks in advance
> 
> Mike McBee
> Signature House
> systems@xxxxxxxxxxxxxxxxxx
> www.signaturehouse.net
> 304-842-3386
> 
> 
> IE STYLESHEET
> <?xml version="1.0"?>
> <?xml-stylesheet type="text/xsl" href="List Nodes - 
> HTML.xsl"?> <xsl:template match="/">
>   <table>
>     <tr><td>Name</td><td>Text</td><td>Period</td></tr>
>     <xsl:for-each select="//*">
>       <tr>
>         <td><xsl:value-of select="name(.)"/></td>
>         <td><xsl:value-of select="normalize-space(text())"/></td>
>         <td><xsl:value-of select="normalize-space(.)"/></td>
>     </tr>
>     </xsl:for-each>
>   </table>
> </xsl:template>
> 
> 
> XML INPUT 1
> <?xml version="1.0"?>
> <?xml-stylesheet?>
> <AAA>
> <BBB>
> <CCC>
> C1
> </CCC>
> B2
> </BBB>
> </AAA>
> 
> 
> XML INPUT 2
> <?xml version="1.0"?>
> <?xml-stylesheet?>
> <AAA><BBB><CCC>C1</CCC>B2</BBB></AAA>
> 
> 
> IE RESULTS FROM BOTH INPUTS
> Name  Text  Period
> AAA         C1 B2
> BBB   B2    C1 B2
> CCC   C1    C1
> 
> 
> FM RESULTS FROM INPUT 1
> Name  Text  Period
> AAA         C1 B2
> BBB         C1 B2
> CCC   C1    C1
> 
> 
> FM RESULTS FROM INPUT 2
> Name  Text  Period
> AAA         C1 B2
> BBB   B2    C1 B2
> CCC   C1    C1

Current Thread