Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>XSLT 2.0</h1> <p>Using XSLT 2.0, the following solution works:</p> <pre><code> &lt;xsl:variable name="map"&gt; &lt;entry key="key-1"&gt;value1&lt;/entry&gt; &lt;entry key="key-2"&gt;value2&lt;/entry&gt; &lt;entry key="key-3"&gt;value3&lt;/entry&gt; &lt;/xsl:variable&gt; &lt;xsl:template match="/"&gt; &lt;output&gt; &lt;xsl:value-of select="$map/entry[@key='key-1']"/&gt; &lt;/output&gt; &lt;/xsl:template&gt; </code></pre> <h1>XSLT 1.0</h1> <p>You cannot use a result tree fragment in a XPath expression in XSLT 1.0, but <code>fn:document()</code> can retrieve map values. An answer to a <a href="https://stackoverflow.com/questions/3564329/how-can-i-select-nodes-from-a-tree-whose-markup-is-stored-in-a-variable/3564550#3564550">similar question</a> will work here:.</p> <pre><code>&lt;xsl:value-of select="document('')//xsl:variable[@name='map']/map/entry[@key='key-1']"/&gt; </code></pre> <p>As described in the <a href="https://www.w3.org/TR/xslt-10/#document" rel="nofollow noreferrer">XSLT 1.0 specification</a>:</p> <blockquote> <p><code>document('')</code> refers to the root node of the stylesheet; the tree representation of the stylesheet is exactly the same as if the XML document containing the stylesheet was the initial source document.</p> </blockquote> <p>However, you don't need to use <code>xsl:variable</code> for this. You could specify your map node directly under <code>xsl:stylesheet</code>, but you must remember that a top level elements must have a non null namespace URI:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="some.uri" exclude-result-prefixes="my"&gt; &lt;my:map&gt; &lt;entry key="key-1"&gt;value1&lt;/entry&gt; &lt;entry key="key-2"&gt;value2&lt;/entry&gt; &lt;entry key="key-3"&gt;value3&lt;/entry&gt; &lt;/my:map&gt; &lt;xsl:template match="/"&gt; &lt;output&gt; &lt;xsl:value-of select="document('')/*/my:map/entry[@key='key-1']"/&gt; &lt;/output&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.
    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