[xsl] Problem Processing Result Tree Fragments

Subject: [xsl] Problem Processing Result Tree Fragments
From: "Schwartz, Rechell R, ALABS" <rrschwartz@xxxxxxx>
Date: Wed, 31 Dec 2003 11:57:49 -0600
All,

I am new at using variable/parameters and am trying to loop through a
result tree fragment and dynamically set some variables to the values of
the result tree fragment, and call a template that process these
variables/parameters. The variables represent names of nodes within the
XMSL document whose values I need to access. I need to compare a user's
old choice to their new choice and compare the results and output them
based on how they compare. I want to re-use this template for many
different types of inputs. I just found out that XSLT does not support
result tree fragments. My project is using the Xalan processor (I have
no influence to suggest another process). Can someone tell me the exact
syntax of how to invoke the proper extension?

Also since I am inexperienced with this, I suspect that there are errors
in my stylesheet. If someone can take a look at the following code
snippet, and make corrections, I would appreciate it.

Rechell Schwartz

<?xml version="1.0" ?>
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="no_oldvalue">
<xsl:text>&lt;null&gt; --&gt; </xsl:text>
</xsl:variable>

<xsl:variable name="no_newvalue">
<xsl:text> --&gt; &lt;null&gt;</xsl:text>
</xsl:variable>

<xsl:variable name="both_values">
<xsl:text> --&gt; </xsl:text>
</xsl:variable>

<xsl:param name="title"/>
<xsl:template match="/">
<html>

<xsl:apply-templates select="color[Old_Color_Information[*] or
Color_Information[*]]"/>

<xsl:template match="color[Old_Color_Information[*] or
Color_Information[*]]">
<xsl:variable name="Section" select="'Color_Information'"/>
<xsl:variable name="Old_Section" select="'Old_Color_Information'"/>
<xsl:variable name="Pairs">
<Field_Label>
<Field>
Name
</Field>
<Label>
Color Name
</Label>
</Field_Label>
<Field_Label>
<Field>
Hue
</Field>
<Label>
Hue
</Label>
</Field_Label>

</xsl:variable>
<xsl:for-each select="$Pairs/Field_Label">
<xsl:variable name="Field" select="Field" />
<xsl:variable name="Label" select="Label" />
<xsl:call-template name="general_template" >
<xsl:with-param name="Section" select="'Color_Information'"/>
<xsl:with-param name="Old_Section" select="'Old_Color_Information'"/>
<xsl:with-param name="Field" select="$Field" />
<xsl:with-param name="Label" select="$Label" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>

<xsl:template name="general_template">
<xsl:param name="Section"/>
<xsl:param name="Old_Section"/>
<xsl:param name="Field"/>
<xsl:param name="Label"/>
<xsl:choose>
<xsl:when test="not($Old_Section[*])">
<xsl:apply-templates select="$Section/$Field[text() != '']"/>
</xsl:when>
<xsl:when test="not($Old_Section/$Field[1]) and $Section/$Field[text()
!= '']">
<tr><td><xsl:value-of select="$Label"/>:</td><td><xsl:value-of
select="$no_oldvalue"/><xsl:value-of
select="$Section/$Label"/></td></tr>
</xsl:when>
<xsl:when test="$Old_Section/$Field[text() != ''] and
not($Section/$Field[1])">
<tr><td><xsl:value-of select="$Label"/>:</td><td> <xsl:value-of
select="$Old_Section/$Field"/><xsl:value-of
select="$no_newvalue"/></td></tr>
</xsl:when>
<xsl:when test="$Old_Section/$Field[text() != ''] and
$Section/$Field[text() != '']  and $Old_Section/$Section/$Field">
<xsl:apply-templates select="$Section/$Field[text() != '']"/>
</xsl:when>
<xsl:otherwise>
<tr><td><xsl:value-of select="$Label"/>:</td><td><xsl:value-of
select="$Old_Section/$Field"/><xsl:value-of
select="$both_values"/><xsl:value-of
select="$Section/$Field"/></td></tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</html>
</xsl:template>
</xsl:stylesheet> 

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


Current Thread