XPath - search by reference
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 1
- Joined: Tue Oct 27, 2015 1:47 pm
XPath - search by reference
Hello!
I have a general question regarding XPath.
How can I search for the value of Object.name in data:One only by knowing the value of Object.name in data:Three, using XPath?
<data:Three abc:ID="3">
<data:Object.name>CCC</data:Object.name>
<data:Object.Container abc:resource="#2"/>
</data:Three>
<data:Two abc:ID="2">
<data:Object.name>BBB</data:Object.name>
<data:Two.Parent abc:resource="#1"/>
</data:Two>
<data:One abc:ID="1">
<data:Object.name>This is the value</data:Object.name>
</data:One>
I have searched manually using:
/abc:ABC/data:Three[data:Object.name/contains(.,'CCC')]
/abc:ABC/data:Two[@abc:ID='2']
/abc:ABC/data:One[@abc:ID='1']
/abc:ABC/data:One[@abc:ID='1']/data:Object.name
However, I would like one XPath query to search for "CCC" (first query) and then follow the abc:resource from "Three" to "One".
Alternatively find all "CCC" that are referenced by a specific data:One element.
Is this possible?
I have a general question regarding XPath.
How can I search for the value of Object.name in data:One only by knowing the value of Object.name in data:Three, using XPath?
<data:Three abc:ID="3">
<data:Object.name>CCC</data:Object.name>
<data:Object.Container abc:resource="#2"/>
</data:Three>
<data:Two abc:ID="2">
<data:Object.name>BBB</data:Object.name>
<data:Two.Parent abc:resource="#1"/>
</data:Two>
<data:One abc:ID="1">
<data:Object.name>This is the value</data:Object.name>
</data:One>
I have searched manually using:
/abc:ABC/data:Three[data:Object.name/contains(.,'CCC')]
/abc:ABC/data:Two[@abc:ID='2']
/abc:ABC/data:One[@abc:ID='1']
/abc:ABC/data:One[@abc:ID='1']/data:Object.name
However, I would like one XPath query to search for "CCC" (first query) and then follow the abc:resource from "Three" to "One".
Alternatively find all "CCC" that are referenced by a specific data:One element.
Is this possible?
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: XPath - search by reference
Hi,
The abc:resource from data:Three is pinpointed like this:
which leads to the second expression (with data:Two/@abc:ID = @abc:resource, with trimmed# ) written like this
and the third (all chained together to pinpoint data:Object.name) like this:
It's not pretty, but it works. Without the # in abc:resource, the XPath would become cleaner since you would not need the replace() functions.
Regards,
Adrian
Using # in the abc:resource value (#1, #2) makes things difficult since you will have to trim the # before searching.However, I would like one XPath query to search for "CCC" (first query) and then follow the abc:resource from "Three" to "One".
The abc:resource from data:Three is pinpointed like this:
Code: Select all
/abc:ABC/data:Three[data:Object.name/contains(.,'CCC')]/data:Object.Container/@abc:resource
Code: Select all
/abc:ABC/data:Two[@abc:ID=replace(/abc:ABC/data:Three[data:Object.name/contains(.,'CCC')]/data:Object.Container/@abc:resource, '^#', '')]
Code: Select all
/abc:ABC/data:One[@abc:ID=replace(/abc:ABC/data:Two[@abc:ID=replace(/abc:ABC/data:Three[data:Object.name/contains(.,'CCC')]/data:Object.Container/@abc:resource, '^#', '')]/data:Two.Parent/@abc:resource, '^#', '')]/data:Object.name
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
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