What makes an XPath String?
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 18
- Joined: Sat Nov 07, 2009 12:03 am
What makes an XPath String?
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
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: What makes an XPath String?
Post by sorin_ristache »
Hello,
Regards,
Sorin
Maybe you should go through an XPath tutorial?Stefan_E wrote: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?)?
The result of an expression like $x2/rec/local-name($elem) is the result of the function local-name() which is the element name: d1 or d2 or rec or top etc.Stefan_E wrote:What confuses me:Hence, what I picture for myself as an XPath string seems to be the wrong concept. But what is the right one?
- 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
Regards,
Sorin
-
- Posts: 18
- Joined: Sat Nov 07, 2009 12:03 am
Re: What makes an XPath String?
Hi Sorin,
thanks for the link to the tutorial; I'm also using the O'Reilly book on XQuery, but I lack the explanation of the concept:
Regards, Stefan
thanks for the link to the tutorial; I'm also using the O'Reilly book on XQuery, but I lack the explanation of the concept:
- my background is perl, so I could expect local-name() to evaluate to d1 and then the whole path string to read <evaluation of $x2> . '/rec/' . <evaluation of local-name>, hence /top/rec/d1, which would then again be taken as an XPath string, leading to the element <d1>30</d1>
- or, as I observe, I only get <evaluation of local-name>; but then I'd expect that somebody throws an error (or at least a warning) because of the unused part $x2/rec/

Regards, Stefan
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service