Re: [xsl] comparing nodesets to each other

Subject: Re: [xsl] comparing nodesets to each other
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 11 Apr 2005 16:35:20 +0100
without seeing what your source xml looks like, or what output format
you want to generate it's fairly impossible to give any specific advice,
but a few observations.

      <xsl:variable name="variation">

this means that $variation will hole a result tree fragment, which means

      <xsl:for-each select="$variation">

will generate an error on a conformant XSLT 1.0  processor, if you are
using XSLT 2, best to say so, as any answeres are likely to be rather
different in that case. For XSLT1 you'd need a node-set extension

In general it's rather hard to define "difference" (see a long thread on
exactly that subject lastweek)

for example if your two fragments are




What do you want to mark as the "difference", is it that an element x
was added (this does actually correspond to the edit I made to generate
the text above) or do you want to mark that the frst child changed from
b to x, the second from c to b, the third from d to c, and a new fourth
child, d added.

Depending on which of those two answers you want, the code is likely to
be radically different. 

         <xsl:if test=". != $compare-node">
            <xsl:copy-of select="."/>
            <xsl:attribute name="different">current</xsl:attribute>

This will always generate an error if teh test is true.
The copy-of . copies an element node, and then xsl:attribute tries to
add an attribute to the currently open node, ie the parent of teh node
just copied, and you can not add attributes to an element once a child
has been added.


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

Current Thread