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">
<xslutput 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>
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">
<xslutput 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>