Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this XSLT</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:key name="Pos" match="Positionen" use="ID" /&gt; &lt;!-- Match Positionen elements normally --&gt; &lt;xsl:template match="Positionen"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*|node()"/&gt; &lt;Path&gt; &lt;!-- Get parent path --&gt; &lt;xsl:apply-templates select="key('Pos', Parent)" mode="parent" /&gt; &lt;!-- End of path --&gt; &lt;xsl:value-of select="ID" /&gt; &lt;/Path&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;!-- Template used to recursively match parents --&gt; &lt;xsl:template match="Positionen" mode="parent"&gt; &lt;xsl:apply-templates select="key('Pos', Parent)" mode="parent" /&gt; &lt;xsl:value-of select="concat(ID, '/')" /&gt; &lt;/xsl:template&gt; &lt;xsl:template match="@*|node()"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*|node()"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>This starts by matching the <strong>Positionen</strong> elements normally, and then recursively matches the parent elements based on the <strong>Parent</strong> value. Note it also makes use of an <strong>xsl:key</strong> to look-up the element by <strong>ID</strong> much quicker.</p> <p>When applied to your sample XML, the following is output:</p> <pre><code>&lt;Positions&gt; &lt;Positionen&gt; &lt;ID&gt;1&lt;/ID&gt; &lt;Parent/&gt; &lt;Path&gt;1&lt;/Path&gt; &lt;/Positionen&gt; &lt;Positionen&gt; &lt;ID&gt;2&lt;/ID&gt; &lt;Parent&gt;1&lt;/Parent&gt; &lt;Path&gt;1/2&lt;/Path&gt; &lt;/Positionen&gt; &lt;Positionen&gt; &lt;ID&gt;3&lt;/ID&gt; &lt;Parent&gt;1&lt;/Parent&gt; &lt;Path&gt;1/3&lt;/Path&gt; &lt;/Positionen&gt; &lt;Positionen&gt; &lt;ID&gt;4&lt;/ID&gt; &lt;Parent&gt;2&lt;/Parent&gt; &lt;Path&gt;1/2/4&lt;/Path&gt; &lt;/Positionen&gt; &lt;Positionen&gt; &lt;ID&gt;5&lt;/ID&gt; &lt;Parent&gt;4&lt;/Parent&gt; &lt;Path&gt;1/2/4/5&lt;/Path&gt; &lt;/Positionen&gt; &lt;Positionen&gt; &lt;ID&gt;6&lt;/ID&gt; &lt;Parent&gt;2&lt;/Parent&gt; &lt;Path&gt;1/2/6&lt;/Path&gt; &lt;/Positionen&gt; &lt;/Positions&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload