Suppose I have the following xml-document:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="FirstLevel">
<xs:unique name="uniqueL2inL1">
<xs:selector xpath="SecondLevel" />
<xs:field xpath="@Name" />
</xs:unique>
</xs:element>
<xs:element name="SecondLevel">
<xs:unique name="uniqueL3inL2">
<xs:selector xpath="ThirdLevel" />
<xs:field xpath="@Name" />
</xs:unique>
</xs:element>
<xs:element name="ThirdLevel">
<xs:unique name="uniqueL4inL3">
<xs:selector xpath="FourthLevel" />
<xs:field xpath="@Name" />
</xs:unique>
</xs:element>
<xs:element name="FourthLevel"/>
</xs:schema>
What possibilities are there to get the "chain" of unique-definitions from the ThirdLevel
element up to the document root in a correct ordering?
The resulting output I wanna have for ThirdLevel
for example:
FirstLevel
SecondLevel
To get the node of FirstLevel
(eg root-element
) I need to query an xs:element
which has an xs:unique
, but whose name itself is nowhere else used in an xs:unique/xs:selector/@xpath
. This specific query is:
<xsl:variable name="root-element" select="//xs:element[xs:unique and not(//xs:element/xs:unique/xs:selector/@xpath = @name)]/@name"/>
Now I need to get all nodes between, say, ThirdLevel
and this $root-element
.
I have a recursively called template
with two parameters (can attach, but left aside for clarity) which outputs all the nodes.
Is it possible to query with one xpath?
Greetings
I am not sure the whole approach makes sense for complex schemas and arbitrary XPath selectors but if the current approach gives you the output you want, only in the wrong order then you could simply store the output in a variable and reverse that variable contents when you output the values: