XMLSpy vs Saxon - XSLT 2.0 differences

Discussion in 'XML' started by mikea_59, Feb 21, 2005.

  1. mikea_59

    mikea_59 Guest

    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>
     
    mikea_59, Feb 21, 2005
    #1
    1. Advertising

  2. 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

    "mikea_59" <> wrote in message
    news:...
    >
    > 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>
    >
     
    Dimitre Novatchev, Feb 21, 2005
    #2
    1. Advertising

  3. 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.

    "mikea_59" <> wrote in message
    news:...
    >
    > 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>
    >
     
    Dimitre Novatchev, Feb 21, 2005
    #3
  4. mikea_59

    ajm Guest

    "mikea_59" <> wrote in message news:<>...
    > 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.
     
    ajm, Feb 21, 2005
    #4
  5. mikea_59

    mikea_59 Guest

    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
     
    mikea_59, Feb 21, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Collin VanDyck

    How to force use of SAXON xslt processor?

    Collin VanDyck, Apr 2, 2004, in forum: Java
    Replies:
    1
    Views:
    652
    Collin VanDyck
    Apr 2, 2004
  2. Collin VanDyck
    Replies:
    1
    Views:
    677
    Collin VanDyck
    Apr 2, 2004
  3. Altova Announcements
    Replies:
    0
    Views:
    663
    Altova Announcements
    May 25, 2004
  4. KaR
    Replies:
    0
    Views:
    669
  5. RolfK
    Replies:
    5
    Views:
    1,457
    Martin Honnen
    Feb 6, 2009
Loading...

Share This Page