RE: [xsl] comparing a part of the XML tree

Subject: RE: [xsl] comparing a part of the XML tree
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 16 Jul 2007 11:44:38 +0100
There's probably a difference in the whitespace. If text nodes aren't
significant, then using selection/* and original/* would be better than
selection/node(), original/node().

You might like to play around with the Saxon-specific version of the
function, saxon:deep-equal(). This has an extra "flags" argument to control
how the comparison is done; the simplest setting is '?' which outputs (by
default to System.err) an explanation of why the result of deep-equal() was
false. There is also an option 'w' which ignores whitespace text nodes at
all levels of the tree. To do this without using extensions, you have to
copy both trees to eliminate the whitespace.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Jethro Borsje [mailto:jethro@xxxxxxxxxxxx] 
> Sent: 16 July 2007 11:21
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] comparing a part of the XML tree
> 
> Hi everybody,
> 
> I can not manage to make the deep-equal function work with 
> the node() function.
> 
> I am usting the following template:
> <xsl:template match="/">
> 	<xsl:choose>
> 		<xsl:when test="deep-equal(body/selection/node(),
> body/original/node())">true</xsl:when>
> 		<xsl:otherwise>false</xsl:otherwise>
> 	</xsl:choose>
> </xsl:template>
> 
> With the following XML as input:
> <body>
> 	<selection>
> 		<z color="blue" flavor="vanilla">test 1</z>
> 	</selection>
> 	<original>
> 		<z color="blue" flavor="vanilla">test 1</z>
> 	</original>
> </body>
> 
> The output of this is "false" (although I expected "true"). 
> The strange thing is that when using the following template 
> the output is "true":
> <xsl:template match="/">
> 	<xsl:choose>
> 		<xsl:when test="deep-equal(body/selection/z,
> body/original/z)">true</xsl:when>
> 		<xsl:otherwise>false</xsl:otherwise>
> 	</xsl:choose>
> </xsl:template>
> 
> So there is probably something wrong with how I use the 
> node() function.
> 
> --
> Best regards,
> Jethro Borsje
> 
> http://www.jborsje.nl
> 
> Jethro Borsje wrote:
> > Hi there,
> > 
> > Yes, that was it. I now implemented Saxon and at least I 
> can run the 
> > application. I will play around with the stylesheet a bit 
> more to see 
> > if I can manage to get it to work...

Current Thread