[xsl] Weird XSLT processor output

Subject: [xsl] Weird XSLT processor output
From: David Carver <d_a_carver@xxxxxxxxx>
Date: Mon, 10 Nov 2003 14:27:28 -0800 (PST)
Okay here is the situation, given the following input XML:
<DGS>
	<BOOKMARKS>
		<TABLEID>
			<BMTABLE>CLAIMANT</BMTABLE>
			<BMDESC>Address 1</BMDESC>
			<BMFIELD>ADDRESS1</BMFIELD>
			<XSLTEMP>&lt;xsl:template
match=&quot;CLAIMANT/ADDRESS1&quot;&gt;&lt;xsl:value-of
select=&quot;.&quot;/&gt;&lt;/xsl:template&gt;</XSLTEMP>
		</TABLEID>
		<TABLEID>
			<BMTABLE>CLAIMANT</BMTABLE>
			<BMDESC>Address 2</BMDESC>
			<BMFIELD>ADDRESS2</BMFIELD>
			<XSLTEMP>&lt;xsl:template
match=&quot;CLAIMANT/ADDRESS2&quot;&gt;&lt;xsl:value-of
select=&quot;.&quot;/&gt;&lt;/xsl:template&gt;</XSLTEMP>
		</TABLEID>
		<TABLEID>
			<BMTABLE>CLAIMANT</BMTABLE>
			<BMDESC>ANUMBER</BMDESC>
			<BMFIELD>ANUMBER</BMFIELD>
			<XSLTEMP>&lt;xsl:template
match=&quot;CLAIMANT/ANUMBER&quot;&gt;&lt;xsl:value-of
select=&quot;.&quot;/&gt;&lt;/xsl:template&gt;</XSLTEMP>
		</TABLEID>
		<TABLEID>
			<BMTABLE>CLMREP</BMTABLE>
			<BMDESC>State</BMDESC>
			<BMFIELD>STATE</BMFIELD>
			<XSLTEMP>&lt;xsl:template
match=&quot;CLMREP/STATE&quot;&gt;&lt;xsl:value-of
select=&quot;.&quot;/&gt;&lt;/xsl:template&gt;</XSLTEMP>
		</TABLEID>
		<TABLEID>
			<BMTABLE>CLMREP</BMTABLE>
			<BMDESC>ID</BMDESC>
			<BMFIELD>REPID</BMFIELD>
			<XSLTEMP>&lt;xsl:template
match=&quot;CLMREP/REPID&quot;&gt;&lt;xsl:value-of
select=&quot;.&quot;/&gt;&lt;/xsl:template&gt;</XSLTEMP>
		</TABLEID>
</BOOKMARKS>
</DGS>

Desired Output format:
<DGS>
   <BOOKMARKS>
        <TABLE tableid="tablename">
            <FIELD fieldid="fieldname">
                 <DESC>description</DESC>
                 <XSLTEMP> </XSLTEMP>
            </FIELD>
        </TABLE>
   </BOOKMARKS>
</DGS>

And the following XSLT's:

(XSLTA)

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:lookup="urn:some.urn" exclude-result-prefixes="lookup">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<lookup:table>
		<BMTABLE>CMSCASE</BMTABLE>
		<BMTABLE>CLAIMANT</BMTABLE>
		<BMTABLE>CLMREP</BMTABLE>
		<BMTABLE>CMSGROUP</BMTABLE>
		<BMTABLE>EMPLOYER</BMTABLE>
		<BMTABLE>EMPREP</BMTABLE>
		<BMTABLE>HEARING</BMTABLE>
		<BMTABLE>HEAROFFCR</BMTABLE>
		<BMTABLE>OTHERCPT</BMTABLE>
		<BMTABLE>SUBPOENA</BMTABLE>
	</lookup:table>
	<xsl:variable name="globalTableNames"
select="document('')/*/lookup:table/*"/>

	<xsl:template match="DGS">
	<xsl:element name="DGS">
	    <xsl:apply-templates select="BOOKMARKS" />
      </xsl:element>
    	</xsl:template>
    	
    	<xsl:template match="BOOKMARKS">
       <xsl:element name="BOOKMARKS">
            <xsl:for-each select="$globalTableNames">
                 <xsl:element name="TABLE">
			  <xsl:attribute name="tableid"><xsl:value-of
select="."/></xsl:attribute>
			  <xsl:variable name="tablename"><xsl:value-of
select="."/></xsl:variable>
     	               <xsl:apply-templates
select="/DGS/BOOKMARKS/TABLEID[BMTABLE = $tablename]"/>
     	          </xsl:element>
     	     </xsl:for-each>
      </xsl:element>
    	</xsl:template>
    	
    	<xsl:template match="TABLEID">
    	   <test/>
    	       <xsl:element name="FIELD">
    	              <xsl:attribute name="fieldid">
    	                  <xsl:value-of select="BMFIELD"/>
    	              </xsl:attribute>
    	              <xsl:element name="DESC">
    	                     <xsl:value-of select="BMDESC"/>
    	               </xsl:element>
    	               <xsl:element name="XSLTEMP">
    	                   <xsl:value-of select="XSLTEMP"/>
    	               </xsl:element>
           </xsl:element>
    	</xsl:template>
</xsl:stylesheet>

(XSLTB)

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:lookup="urn:some.urn" exclude-result-prefixes="lookup">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<lookup:table>
		<BMTABLE>CMSCASE</BMTABLE>
		<BMTABLE>CLAIMANT</BMTABLE>
		<BMTABLE>CLMREP</BMTABLE>
		<BMTABLE>CMSGROUP</BMTABLE>
		<BMTABLE>EMPLOYER</BMTABLE>
		<BMTABLE>EMPREP</BMTABLE>
		<BMTABLE>HEARING</BMTABLE>
		<BMTABLE>HEAROFFCR</BMTABLE>
		<BMTABLE>OTHERCPT</BMTABLE>
		<BMTABLE>SUBPOENA</BMTABLE>
	</lookup:table>
	<xsl:variable name="globalTableNames"
select="document('')/*/lookup:table/*"/>
	<xsl:template match="DGS">
		<xsl:element name="DGS">
			<xsl:apply-templates select="BOOKMARKS"/>
		</xsl:element>
	</xsl:template>
	<xsl:template match="BOOKMARKS">
		<xsl:element name="BOOKMARKS">
			<xsl:variable name="bookmarks" select="TABLEID"/>
			<xsl:for-each select="$globalTableNames">
				<xsl:element name="TABLE">
					<xsl:attribute name="tableid"><xsl:value-of
select="."/></xsl:attribute>
					<xsl:variable name="tablename">
						<xsl:value-of select="."/>
					</xsl:variable>
					<xsl:variable name="tempNodeset" select="$bookmarks[BMTABLE =
$tablename]"/>
					<xsl:apply-templates select="$tempNodeset"/>
				</xsl:element>
			</xsl:for-each>
		</xsl:element>
	</xsl:template>
	
	<xsl:template match="TABLEID">
		<xsl:element name="FIELD">
			<xsl:attribute name="fieldid"><xsl:value-of
select="BMFIELD"/></xsl:attribute>
			<xsl:element name="DESC">
				<xsl:value-of select="BMDESC"/>
			</xsl:element>
			<xsl:element name="XSLTEMP">
				<xsl:value-of select="XSLTEMP"/>
			</xsl:element>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>


When run under XML Spy Enterprise 2004, XSLTA and XSLTB both produce
the same desired output.  However, when XSLTA is run under LibXSLT,
Sablotron, and MSXML (have not tested xalan or saxon), the following
output is produced:

<DGS>
   <BOOKMARKS>
      <TABLE tableid="tablename"/>
      <TABLE tableid="tablename"/>
   </BOOKMARKS>
</DGS>

My question is, is XML Spy producing the correct output for XSLTA or
are the other three processors not implementing the transformation
correctly?

Dave


=====
"...there is nothing stranger than people." - Anonymous

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread