[xslt] Incorrect output using -o option (All info - long post)



Hi all,
A new post about this problem, with all the information included this time.

I have defined an element that includes the <body> contents of a file, using the document() function. I have written the corresponding stylesheet transformations and verified their proper operation using xsltproc writing to stdout, and redirecting stdout to a file.

The command line I use is this:
xsltproc --novalid stylesheet.xsl test.xml >expectedXform.xml

Contents of test.xml:
-------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
      "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";>
      <html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 <title>Title is required by xhtml DTD</title>
</head>
<body>
   <form>
       <imlformcomponent href="snentry.xml" />
   </form>
</body>
</html>
-------------------------------------------------

Contents of snentry.xml (the file that is included by test.xml):
-------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";>
<html>
<head>
<title>SerialNumberEntryTable</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<!--<table style="margin: auto; padding: 1em; text-align: center;" align="center">-->
<table style="margin: auto; padding: 1em; text-align: center;" >
<tr><td align="center" colspan="2">Serial Number Entry</td></tr>
<tr><td align="right" rowspan="3"><img alt="Logo GIF goes here" /></td>
<td align="left" valign="bottom">Please enter your serial number</td></tr>
<tr><td align="left"><input type="text" /></td></tr>
<tr><td align="left" valign="bottom">
<table>
<tr>
<td valign="bottom"><button type="button" title="Back button help" /><imlstring imlBind="(BackButtonText)">Back</imlstring></td>
<td><!-- &nbsp; --></td>
<td valign="bottom"><button type="submit" title="Next button help" /><imlstring imlBind="(BackButtonText)">Next</imlstring></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
-------------------------------------------------


Contents of stylesheet.xsl:
-------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
               xmlns:exslt="http://exslt.org/common";
               version="1.0"
>
<xsl:output method="xml" />

<!--=======================================================================================
Template for processing the root node. Just process all children.
========================================================================================-->
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>


<!--=======================================================================================
Template for matching any old element. Just copy the element and all of its attributes (but
not its children) to the output, then process all of the children.
========================================================================================-->
<xsl:template name="CloneElementTemplate" match="*">
<xsl:element name="{name()}">
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:element>
</xsl:template>


<!--=======================================================================================
Templates for matching an imlformcomponent element.
========================================================================================-->
<xsl:template priority="1.0" match="//body" mode="forminclude">
<xsl:comment>Template match for /html/body</xsl:comment>
<xsl:apply-templates />
</xsl:template>


   <xsl:template priority="1.0" match="//head" mode="forminclude">
       <xsl:comment>Template match for /html/head</xsl:comment>
   </xsl:template>


<xsl:template match="/" mode="forminclude"> <xsl:comment>Template match for /</xsl:comment> <xsl:apply-templates mode="forminclude" /> </xsl:template>

<xsl:template name="FormIncludeElementWildcard" priority="0.5" match="*" mode="forminclude">
<xsl:comment>Template match for *: element type is:<xsl:value-of select="name()" /></xsl:comment>
<xsl:apply-templates mode="forminclude"/>
</xsl:template>


<xsl:template name="FormComponentInclude" priority="1.0" match="imlformcomponent">
<xsl:comment>Template match for imlformcomponent</xsl:comment>
<xsl:variable name="formcomponentfilename">
<xsl:value-of select="@href" />
</xsl:variable>
<xsl:comment>value-of href is: <xsl:value-of select="$formcomponentfilename" /></xsl:comment>
<!--
<xsl:apply-templates select="document(string($formcomponentfilename))" mode="forminclude"/>
-->
<xsl:variable name="contents" select="document(string($formcomponentfilename))" />
<xsl:apply-templates select="exslt:node-set($contents)" mode="forminclude" />
</xsl:template>


</xsl:stylesheet>
-------------------------------------------------

Contents of expectedXform.xml (the correct transformation):
-------------------------------------------------
<?xml version="1.0"?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Title is required by xhtml DTD</title>
</head>
<body>
<form>
<!--Template match for imlformcomponent--><!--value-of href is: snentry.xml--><!--Template match for /--><!--Template match for *: element type is:html-->
<!--Template match for /html/head-->
<!--Template match for /html/body-->


<table style="margin: auto; padding: 1em; text-align: center;">
<tr><td align="center" colspan="2">Serial Number Entry</td></tr>
<tr><td align="right" rowspan="3"><img alt="Logo GIF goes here"/></td>
<td align="left" valign="bottom">Please enter your serial number</td></tr>
<tr><td align="left"><input type="text"/></td></tr>
<tr><td align="left" valign="bottom">
<table>
<tr>
<td valign="bottom"><button type="button" title="Back button help"/><imlstring imlBind="(BackButtonText)">Back</imlstring></td>
<td/>
<td valign="bottom"><button type="submit" title="Next button help"/><imlstring imlBind="(BackButtonText)">Next</imlstring></td>
</tr>
</table>
</td>
</tr>
</table>



</form> </body> </html> -------------------------------------------------

The problem I see is that if I use the -o option to write a file, I get incorrect results. For instance, the command line:
xsltproc --novalid -o xform.xml stylesheet.xsl test.xml


gives the following contents for xform.xml (the incorrect transformation):
-------------------------------------------------
<?xml version="1.0"?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Title is required by xhtml DTD</title>
</head>
<body>
<form>
<!--Template match for imlformcomponent--><!--value-of href is: snentry.xml--><!--Template match for /--><!--Template match for *: element type is:html-->
<!--Template match for *: element type is:head-->
<!--Template match for *: element type is:title-->SerialNumberEntryTable
<!--Template match for *: element type is:meta-->


<!--Template match for *: element type is:body-->

<!--Template match for *: element type is:table-->
<!--Template match for *: element type is:tr--><!--Template match for *: element type is:td-->Serial Number Entry
<!--Template match for *: element type is:tr--><!--Template match for *: element type is:td--><!--Template match for *: element type is:img-->
<!--Template match for *: element type is:td-->Please enter your serial number
<!--Template match for *: element type is:tr--><!--Template match for *: element type is:td--><!--Template match for *: element type is:input-->
<!--Template match for *: element type is:tr--><!--Template match for *: element type is:td-->
<!--Template match for *: element type is:table-->
<!--Template match for *: element type is:tr-->
<!--Template match for *: element type is:td--><!--Template match for *: element type is:button--><!--Template match for *: element type is:imlstring-->Back
<!--Template match for *: element type is:td-->
<!--Template match for *: element type is:td--><!--Template match for *: element type is:button--><!--Template match for *: element type is:imlstring-->Next








</form>
</body>
</html>
-------------------------------------------------
I have a fallback wildcard match template that generated the comment output. None of the templates that were matched when output was going to stdout have been matched in this case. (Without the wildcard template, all I get is blank lines and raw text from the included file.) I also observe that the incorrect case takes at least 10 times as long to complete as the correct case.


I have run with the --debug option in both cases. Everything is identical until the included file processing starts. After that, the incorrect case doesn't find any of the template matches that were found in the correct case.

I get the following information from "xsltproc --version":
Using libxml 20615, libxslt 10112 and libexslt 810
xsltproc was compiled against libxml 20615, libxslt 10112 and libexslt 810
libxslt 10112 was compiled against libxml 20615
libexslt 810 was compiled against libxml 20615

I am running on a dual G5 Power Mac under Mac OS 10.3.8 with all updates installed.

This looks like a bug to me, but I'm a relative newbie to this stuff. Any help with this would be greatly appreciated.

Regards,
Rush



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]