What makes an XPath String?
Posted: Sun Nov 08, 2009 2:34 pm
I'm a newbie to XQuery and XPath. I'm trying to compare two XML structures. The problem I now have: What exactly makes an XPath (string?)?
I have the following code:
which produces
So far so good, but it took me a while to get there. Specifically, in my original trials, I had something like
What confuses me:
Thanks for your help! Stefan
I have the following code:
Code: Select all
declare variable $x1 := <top>
<rec>
<d1>25</d1>
<d2>10</d2>
</rec>
</top>;
declare variable $x2 := <top>
<rec>
<d1>30</d1>
<d2>10</d2>
</rec>
</top>;
for $node in $x1/rec
return for $elem in $node/*
return if ($elem = $x2/rec/*[local-name()=local-name($elem)])
then (<match>{$elem}</match>)
else (<diff>{$elem}</diff>)
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<diff>
<d1>25</d1>
</diff>
<match>
<d2>10</d2>
</match>
Code: Select all
return if ($elem = $x2/rec/local-name($elem))
then (<match>{$elem}</match>)
else (<diff>{$elem}</diff>)
- Checking with the debugger, I find local-name(elem) = 'd1'
- but also $x2/rec/local-name($elem) evaluates to 'd1' (rather than what I expected: 30
Thanks for your help! Stefan