xsl-list
[Top] [All Lists]

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

2007-07-16 01:51:10
deep-equal() is an XSLT 2.0 / XPath 2.0 function, you're trying to use it
with Xalan which only implements 1.0.

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

-----Original Message-----
From: Jethro Borsje [mailto:jethro(_at_)jesdesign(_dot_)nl] 
Sent: 16 July 2007 09:45
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] comparing a part of the XML tree

I want to match the nodes *inside* the <selection> node 
against the 
nodes *inside* the original node.

deep-equal(selection/node(),$original/node())

Alright, that sounds logical. I assume that in this case 
$original is a variable that refers to the <original> element 
in the input XML file?

I constantly get an error like this when trying to use the deep-equal
function:
[error]
ERROR:  'Error checking type of the expression 
'funcall(deep-equal, 
[ParentLocationPath(ParentLocationPath(step("child", 14), 
step("child", 15)), step("child", -1)), 
ParentLocationPath(ParentLocationPath(step("child", 14), 
step("child", 15)), step("child", -1))])'.'
FATAL ERROR:  'Could not compile stylesheet'
Error creating transformer
javax.xml.transform.TransformerConfigurationException: Could 
not compile stylesheet
      at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactor
yImpl.newTemplates(TransformerFactoryImpl.java:824)
      at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactor
yImpl.newTransformer(TransformerFactoryImpl.java:613)
      at Main.getTransformer(Main.java:128)
      at Main.compare(Main.java:70)
      at Main.<init>(Main.java:44)
      at Main.main(Main.java:53)
------------------------------------
Parsing body[<compare><selection><z color="blue" 
flavor="vanilla">testje</z></selection><original><e><x color="red" 
flavor="chocolate">testje 2</x><z color="blue" 
flavor="vanilla">testje</z></e></original></compare>]
Exception in thread "main" java.lang.NullPointerException
      at Main.compare(Main.java:79)
      at Main.<init>(Main.java:44)
      at Main.main(Main.java:53)
[/error]

This is my stylesheet:
[stylesheet]
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet 
version="2.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

      <xsl:template match="/">
              <xsl:choose>
                      <xsl:when 
test="deep-equal(compare/selection/node(),
compare/selection/node())">true</xsl:when>
                      <xsl:otherwise>false</xsl:otherwise>
              </xsl:choose>
      </xsl:template>
</xsl:stylesheet>
[/stylesheet]
As you can see I am trying to compare the node inside the 
selection element to itself, just to check if everything is working.

This is the input:
[input]
<compare>
<selection>
      <z color="blue" flavor="vanilla">testje</z> 
</selection> <original>
      <e>
              <x color="red" flavor="chocolate">testje 2</x>
              <z color="blue" flavor="vanilla">testje</z>
      </e>
</original>
</compare>
[/input]

--
Best regards,
Jethro Borsje

http://www.jborsje.nl

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--