Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>I. This simple and efficient XSLT 1.0 transformation (no variables and no post-processing of results):</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:template match="/*"&gt; &lt;Year&gt; &lt;xsl:apply-templates/&gt; &lt;/Year&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Movies"&gt; &lt;MovieList&gt; &lt;xsl:apply-templates/&gt; &lt;/MovieList&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Add"&gt; &lt;xsl:value-of select="substring('*,', 2 - (position()=1),1)"/&gt; &lt;xsl:value-of select="concat(Key, '-', Value)"/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on the provided XML document:</strong></p> <pre><code>&lt;Year&gt; &lt;Movies&gt; &lt;Add&gt; &lt;Key&gt;movie1&lt;/Key&gt; &lt;Value&gt;black&lt;/Value&gt; &lt;/Add&gt; &lt;Add&gt; &lt;Key&gt;movie2&lt;/Key&gt; &lt;Value&gt;white&lt;/Value&gt; &lt;/Add&gt; &lt;/Movies&gt; &lt;/Year&gt; </code></pre> <p><strong>produces the wanted, correct result:</strong></p> <pre><code>&lt;Year&gt; &lt;MovieList&gt;*movie1-black,movie2-white&lt;/MovieList&gt; &lt;/Year&gt; </code></pre> <hr> <p><strong>II. XSLT 2.0 Solution:</strong></p> <pre><code>&lt;xsl:stylesheet version="2.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:template match="/*"&gt; &lt;Year&gt; &lt;xsl:apply-templates/&gt; &lt;/Year&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Movies"&gt; &lt;MovieList&gt; &lt;xsl:sequence select="'*'[current()/Add]"/&gt; &lt;xsl:value-of select="Add/concat(Key, '-', Value)" separator=","/&gt; &lt;/MovieList&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre>
    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.
 

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