Differences between XSL engines

M

mikea_59

I continue to see diferences between XSLT 2.0 engines. Specifically
XMLSpy 2005 and Saxon. I have been using XMLSpy to develop some XSLT
because of the nice debugging environment. When I move my code to Saxon
I often get something completely different. I'm still a newbie to XSL
so I'm not sure which one is correct (I lean towards Saxon, but I'm not
sure). Here is the latest case in point.

I have the following simple example of an input xml file:

<ROOT >
<MAIN>
<flag1>CC</flag1>
<flag2>BB</flag2>
<flag3></flag3>
</MAIN>
</ROOT>

This is the desired output:

flag1=CC flag2=BB


and here is the XSL:

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="text" omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:apply-templates select="//*"/>
</xsl:template>
<xsl:template match="*">
<xsl:if test="text()">
<xsl:value-of select="name()"/>=<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>


In XMLSpy I get the desired output:

flag1=CC flag2=BB


In Saxon I get this:

ROOT=

CC
BB


MAIN=
CC
BB

flag1=CC flag2=BB

This seems like a really simple translation but I can't get it to
work in Saxon. I can't take advantage of element names because thay are
not fixed - although the pattern is consistent the element names change
for each xml instance file. Can someone point out why I am getting
different results. How can I get the desired output in Saxon?
 
D

David Carlisle

I would guess that xml spy is using MXSML. That parser has a documented
non-conformance to the XML specification in its default state.
It discards white space text nodes.
To get a conformant XML parser you need to set the presevewhitespace
property to true.

In this case you probably want to discard the white space text nodes,
but the parser is not supposed to do it by default (and saxon is giving
the right answer)

add <xsl:strip-space elements="*"/> to remove white space text nodes
from the input.


David
 
M

mikea_59

XMLSpy uses it's own parser by default.

I added the <xsl:strip-space elements="*"/> and that worked in Saxon,
thanks a bunch!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top