This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

XSLTC Translets with key() and variables


I am attempting to perform a comparison of nodesets in two versions of an xml file and produce an output consisting of
only new nodes or nodes that have been altered in the newer version.

The transformation works fine when performed in Xalan-J 2.4, but when I attempt to compile the stylesheet into an XSLTC translet, the output produced contains merely whitespace where the new and edited nodes should be. I hope it's okay to raise an XSLTC question on this list.

The relevant section of my stylesheet is as follows:

<xsl:for-each select="*">
<xsl:variable name="id" select="description/id"/>
<xsl:variable name="property" select="."/>
xsl:for-each select="$old_file">
<xsl:if test="not(key('id_group', $id) = $property)">
<xsl:copy-of select="$property"/>
</xsl:if>
</xsl:for-each>
</xsl:for-each>

This section of the stylesheet is based on my understanding of an example from Mike Kay's XSLT Programmer's Reference, although I may be applying those ideas improperly.

The <id> uniquely identifies the "property" in question. New id values indicate new nodes. I am attempting to compare nodes from the two documents whose <id>'s match.

The $old_file variable is a reference to the previous version of the file, which I assign using the document() function on a parameter passed in to the stylesheet:
<xsl:variable name="old_file" select="document($oldfile)" />

The 'id_group' key matches "property" elements using their <id> child. I use the nested for-each to make the old file the current node, and when I perform this transformation uncompiled, the xsl:if test compares the current property to the property in the old file that shares its id.

When the stylesheet is compiled (which Xalan does without complaint), the value of $property within the template body of xsl:if seems to be voided. Whether I use xsl:copy-of or xsl:value-of, the result is simply whitespace. In addition, the xsl:if test is returning true for every node in the files, even though the great majority of them are identical. This behavior leads me to assume that the value of $property is null (or just whitespace) when it is referenced in the "test" attribute of xsl:if as well.

I checked the bug reports in bugzilla for Xalan Java-2 and came across this bug report which seemed to the point:
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1430

According to the notes in the bug report, however, this bug has been repaired.

Am I missing something obvious here? If the problem is in Xalan and not in my stylesheet, is there a conceivable workaround?

Thanks very much,
Troy Thibodeaux

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]