XMLSpy vs Saxon - XSLT 2.0 differences

M

mikea_59

I'm getting different results from XMLSpy and Saxon translations -
both are updated versions. Maybe someone here can give me some insight.

Here is my input:

<MESSAGE>
<msgName>
<B enum="1">
<C>"1234"</C>
</B>
</msgName>
</MESSAGE>

This is what I get from XMLSpy - (this is what I want)

do=msgName B.1.C="1234"

This is what I get in Saxon - (this isn't what I want)

do=msgName B.1.B.1.C="1234" B.1

Here is my XSLT, it'll handle more complex inputs than the one shown
here - (I think this could be greatly improved, but it was working in
XMLSpy and it's not working in my target environment (Saxon), and I'd
like to know why)

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2004/07/xpath-functions"
xmlns:xdt="http://www.w3.org/2004/07/xpath-datatypes">
<xsl:eek:utput method="text" omit-xml-declaration="yes" />

<xsl:template match="/">do=<xsl:value-of select="name(/*/*)"/>
<xsl:text> </xsl:text>
<xsl:for-each select="/*/*/*">
<xsl:call-template name="nameValue"/>
</xsl:for-each>
</xsl:template>

<xsl:template name="nameValue">
<xsl:if test="not(*) and .">
<xsl:value-of select="name(.)"/>
<xsl:if test="@enum">
<xsl:text>.</xsl:text>
<xsl:value-of select="@enum"/>
</xsl:if>
<xsl:if test="not(empty(text()))">
<xsl:text>=</xsl:text>
<xsl:value-of select="."/>
</xsl:if>
</xsl:if>
<xsl:if test="@enum">
<xsl:if test="*">
<xsl:for-each select="node()">
<xsl:call-template name="enum"/>
</xsl:for-each>
</xsl:if>
</xsl:if>
<xsl:if test="empty(.) and (empty(@enum))" >
<xsl:value-of select="name(.)"/>
</xsl:if>
<xsl:text> </xsl:text>
</xsl:template>

<xsl:template name="enum">
<xsl:for-each select="ancestor::*">
<xsl:if test="(name(.) != name(/*)) and (name(.) != name(/*/*))">
<xsl:value-of select="name(.)"/>.<xsl:value-of
select="@enum"/>.</xsl:if>
</xsl:for-each>
<xsl:if test="text()">
<xsl:call-template name="nameValue"/>
</xsl:if>
</xsl:template>

</xsl:stylesheet>
 
D

Dimitre Novatchev

So what's your transformation essentially doing? Nobody can tell why you
don't get the wanted results without an explanation what the code is
expected to do.

Cheers,
Dimitre Novatchev
 
D

Dimitre Novatchev

It appears that the parser used by XMLSpy (or the XSLT processor) discards
whitespace-only text nodes, or doesn't correctly evaluatee the node-test
node().

To get the wanted result with Saxon, change:
<xsl:for-each select="node()">
<xsl:call-template name="enum"/>
</xsl:for-each>

to

<xsl:for-each select="*">
<xsl:call-template name="enum"/>
</xsl:for-each>


Cheers,

Dimitre Novatchev.
 
A

ajm

mikea_59 said:
I'm getting different results from XMLSpy and Saxon translations -
both are updated versions. Maybe someone here can give me some insight.

it is of course not really an XMLSpy vs. Saxon thing but depends
on what parser you have configured XMLSpy to use (by default it
uses the Microsoft parser) - can you confirm which parser you are
using in XMLSpy ?

ajm.
 
M

mikea_59

I am using the default parser in XMLSpy - the built-in XSLT. I don't
have MSXML installed, I don't believe it supports XSLT 2.0.

As far as describing what I'm doing, well, the complete specification
is fairly complicated and I'm struggling with just specifying an
example here to solicit help. For this part of the translation I'm
trying to turn an XML structure into a text based tagged value kind of
structure.

As in my original example:
<MESSAGE>
<msgName>
<B enum="1">
<C>"1234"</C>
</B>
</msgName>
</MESSAGE>

Should turn into this:

do=msgName B.1.C="1234"

A little more complex example:

<MESSAGE>
<msgName>
<B enum="1">
<C>"1234"</C>
<D>"5"</D>
<E enum="1">"6"</E>
</B>
<X/>
</msgName>
</MESSAGE>

Should return:

do=msgName B.1.C="1234" B.1.D="5" B.1.E.1="6" X


Anyway, it looks like Dimitre's suggestion worked in Saxon

Thank you
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top