Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>This transformation</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:in="http://www.composite.net/ns/transformation/input/1.0"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:key name="kIsRootByPageId" match="isroot" use="@PageId"/&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:template match="in:result[1]/Page"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*"/&gt; &lt;xsl:copy-of select="key('kIsRootByPageId',@Id )/@isroot"/&gt; &lt;xsl:apply-templates select="node()"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="in:result[2]"/&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on the provided XML document:</strong></p> <pre><code>&lt;in:inputs xmlns:in="http://www.composite.net/ns/transformation/input/1.0"&gt; &lt;in:result name="SitemapXml"&gt; &lt;Page Id="a0a47ce1-6eba-4d29-a7a3-3749c768c7e7" isopen="true" xmlns=""&gt;&lt;/Page&gt; &lt;Page Id="a3055286-0e90-4b04-99dd-fb1a61dde0bf" isopen='true' xmlns=""&gt; &lt;Page Id="da675b13-d4d3-42ab-acc1-82e2a5408100" isopen='true' iscurrent='true' Depth="2"/&gt;&lt;/Page&gt; &lt;/in:result&gt; &lt;in:result name="GetisrootXml"&gt; &lt;isroot PageId="a0a47ce1-6eba-4d29-a7a3-3749c768c7e7" Id="f8d4eea4-7070-4bc3-a804-e106697ffaa9" isroot="true" xmlns=""/&gt; &lt;isroot PageId="f8e4adbc-2758-42d6-bc40-0192ba0107a6" Id="db62e132-3f3b-493f-917a-9e090f887f13" isroot="false" xmlns=""/&gt; &lt;/in:result&gt; &lt;/in:inputs&gt; </code></pre> <p><strong>produces the wanted, correct result</strong>:</p> <pre><code>&lt;in:inputs xmlns:in="http://www.composite.net/ns/transformation/input/1.0"&gt; &lt;in:result name="SitemapXml"&gt; &lt;Page Id="a0a47ce1-6eba-4d29-a7a3-3749c768c7e7" isopen="true" isroot="true"/&gt; &lt;Page Id="a3055286-0e90-4b04-99dd-fb1a61dde0bf" isopen="true"&gt; &lt;Page Id="da675b13-d4d3-42ab-acc1-82e2a5408100" isopen="true" iscurrent="true" Depth="2"/&gt; &lt;/Page&gt; &lt;/in:result&gt; &lt;/in:inputs&gt; </code></pre> <p><strong>Explanation</strong>:</p> <ol> <li><p>The <strong><a href="http://dpawson.co.uk/xsl/sect2/identity.html" rel="nofollow">identity rule</a></strong> copies "as-is" every node for which this template is selected for execution.</p></li> <li><p>There are two overriding templates, the second of which "deletes" with its empty body the second occurence of <code>in:result</code>.</p></li> <li><p>The first overriding template matches any <code>Page</code> that is a child of the first occurence of <code>in:result</code>. We use keys to efficiently and conveniently find the <code>isroot</code> element that references the current <code>Page</code> in its <code>PageId</code> attribute -- and we copy its <code>isroot</code> attribute.</p></li> </ol>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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