get node depending of parent position (but nodename of parent is unknown)
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 30
- Joined: Wed Feb 14, 2018 3:27 pm
get node depending of parent position (but nodename of parent is unknown)
Post by mariomueller »
Hi all,
we have different XML files where we want to extract the value of a node with name <S_NAD> depending on the current position
We know that <S_NAD>-node is a grandchild of the root. Example
The difficulty is, that the nodename of the child of the root varies. In the example it is: <unknownName>
I wrote a XPATH, but this works wrong:
But this gives me:
1) XPath Location: /book[1]/unknownName[1]
2) XPath Location: /book[1]/unknownName[2]
where I only expected the first line.
Could anybody please help?
Thanks
Regards Mario
we have different XML files where we want to extract the value of a node with name <S_NAD> depending on the current position
We know that <S_NAD>-node is a grandchild of the root. Example
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<book>
<unknownName>
<S_NAD>some content</S_NAD>
</unknownName>
<unknownName>
<S_NAD>some content</S_NAD>
</unknownName>
</book>
The difficulty is, that the nodename of the child of the root varies. In the example it is: <unknownName>
I wrote a XPATH, but this works wrong:
Code: Select all
/*/*/S_NAD/parent::*[position()=1]
1) XPath Location: /book[1]/unknownName[1]
2) XPath Location: /book[1]/unknownName[2]
where I only expected the first line.
Could anybody please help?
Thanks
Regards Mario
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: get node depending of parent position (but nodename of parent is unknown)
Hi Mario,
Some parentheses might help:
in order to first compute the entire sequence of parents and then to select from them the first one.
Or you can also try something like:
Regards,
Radu
Some parentheses might help:
Code: Select all
(/*/*/S_NAD/parent::*)[position() = 1]
Or you can also try something like:
Code: Select all
/*/*/S_NAD[parent::*[count(preceding-sibling::*) = 1]]
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
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