Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>A complete, efficient and short transformation, using keys</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:key name="kBibById" match="bib" use="@id"/&gt; &lt;xsl:template match="node()|@*" name="identity"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="link"&gt; &lt;xsl:call-template name="identity"/&gt; &lt;year&gt;&lt;xsl:value-of select="key('kBibById', @id)"/&gt;&lt;/year&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>When this transformation is applied on the provided XML document:</strong></p> <pre><code>&lt;comp&gt; &lt;alink&gt; &lt;link id="0003"/&gt; &lt;link id="0001"/&gt; &lt;link id="0002"/&gt; &lt;/alink&gt; &lt;bibsection&gt; &lt;bib id="0001"&gt;2007&lt;/bib&gt; &lt;bib id="0002"&gt;2008&lt;/bib&gt; &lt;bib id="0003"&gt;2009&lt;/bib&gt; &lt;/bibsection&gt; &lt;/comp&gt; </code></pre> <p><strong>the wanted, correct result is produced:</strong></p> <pre><code>&lt;comp&gt; &lt;alink&gt; &lt;link id="0003"/&gt; &lt;year&gt;2009&lt;/year&gt; &lt;link id="0001"/&gt; &lt;year&gt;2007&lt;/year&gt; &lt;link id="0002"/&gt; &lt;year&gt;2008&lt;/year&gt; &lt;/alink&gt; &lt;bibsection&gt; &lt;bib id="0001"&gt;2007&lt;/bib&gt; &lt;bib id="0002"&gt;2008&lt;/bib&gt; &lt;bib id="0003"&gt;2009&lt;/bib&gt; &lt;/bibsection&gt; &lt;/comp&gt; </code></pre> <p><strong>Explanation</strong>:</p> <ol> <li><p>The <strong><a href="http://www.dpawson.co.uk/xsl/sect2/identity.html" rel="nofollow">identity rule</a></strong> copies every matched node "as-is".</p></li> <li><p>There is a single template overriding the identity template -- and it matches any <code>link</code> element. The code in the body of this template calls the identity template by name to process the matched <code>link</code> element, then constructs a <code>year</code> element, with a text node child whose value is the string value of the first <code>bib</code> element whose <code>id</code> attribute has the same value as the <code>id</code> attribute of the matched <code>link</code> element. Selecting this <code>bib</code> element is done using the <strong><a href="http://www.w3.org/TR/1999/REC-xslt-19991116#function-key" rel="nofollow"><code>key()</code></a></strong> function that references an <strong><a href="http://www.w3.org/TR/1999/REC-xslt-19991116#key" rel="nofollow"><code>xsl:key</code></a></strong> instruction named "kBibById".</p></li> </ol> <p><strong>Notice</strong>:</p> <p>The link to the identity rule above is temporarily inoperable -- for the time-being, please, use this one form the Internet Archives: </p> <p><a href="http://web.archive.org/web/20081229160200/http://www.dpawson.co.uk/xsl/sect2/identity.html" rel="nofollow">http://web.archive.org/web/20081229160200/http://www.dpawson.co.uk/xsl/sect2/identity.html</a></p>
    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.
 

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