Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Instead of specifying all the elements to order within a template, you may use in a more declarative way a "lookup list" embedded in the stylesheet:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="my-namespace" exclude-result-prefixes="my"&gt; &lt;xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/&gt; &lt;my:Top&gt; &lt;my:A&gt; &lt;my:AA/&gt; &lt;my:AB/&gt; &lt;my:AC/&gt; &lt;/my:A&gt; &lt;my:B/&gt; &lt;my:C/&gt; &lt;my:D/&gt; &lt;/my:Top&gt; &lt;xsl:template match="my:*"&gt; &lt;xsl:param name="source"/&gt; &lt;xsl:variable name="current-lookup-elem" select="current()"/&gt; &lt;xsl:for-each select="$source/*[name()=local-name($current-lookup-elem)]"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="$current-lookup-elem/*"&gt; &lt;xsl:with-param name="source" select="current()"/&gt; &lt;/xsl:apply-templates&gt; &lt;xsl:copy-of select="text()"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/Top"&gt; &lt;xsl:apply-templates select="document('')/*/my:*"&gt; &lt;xsl:with-param name="source" select="/"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>This sample:</p> <pre><code>&lt;Top&gt; &lt;A&gt; &lt;AC/&gt; &lt;AA/&gt; &lt;/A&gt; &lt;D/&gt; &lt;B/&gt; &lt;C&gt;yyy&lt;/C&gt; &lt;A&gt; &lt;AB/&gt; &lt;AC/&gt; &lt;AA&gt;xxx&lt;/AA&gt; &lt;/A&gt; &lt;/Top&gt; </code></pre> <p>will return:</p> <pre><code>&lt;Top&gt; &lt;A&gt; &lt;AA&gt;xxx&lt;/AA&gt; &lt;AC/&gt; &lt;/A&gt; &lt;A&gt; &lt;AA/&gt; &lt;AB/&gt; &lt;AC/&gt; &lt;/A&gt; &lt;B/&gt; &lt;C&gt;yyy&lt;/C&gt; &lt;D/&gt; &lt;/Top&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.
    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