Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To #1: Variables are valid within their parent element only. Which means you must put the logic <em>inside</em> the variable instead of "around" it:</p> <pre><code>&lt;xsl:variable name="var"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="some_test"&gt; &lt;xsl:text&gt;HEY!&lt;/xsl:text&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:text&gt;SEE YA!&lt;/xsl:text&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:variable&gt; </code></pre> <p>To #2: Use parameters to transport values into templates.</p> <pre><code>&lt;xsl:template match="/"&gt; &lt;xsl:variable name="var" select="'something'" /&gt; &lt;!-- params work for named templates.. --&gt; &lt;xsl:call-template name="search"&gt; &lt;xsl:with-param name="p" select="$var" /&gt; &lt;/xsl:call-template&gt; &lt;!-- ...and for normal templates as well --&gt; &lt;xsl:apply-templates select="xpath/to/nodes"&gt; &lt;xsl:with-param name="p" select="$var" /&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:template&gt; &lt;!-- named template --&gt; &lt;xsl:template name="search"&gt; &lt;xsl:param name="p" /&gt; &lt;!-- does stuff with $p --&gt; &lt;/xsl:template&gt; &lt;-- normal template --&gt; &lt;xsl:template match="nodes"&gt; &lt;xsl:param name="p" /&gt; &lt;!-- does stuff with $p --&gt; &lt;/xsl:template&gt; </code></pre> <p>To transport a value back to the calling template, combine the above:</p> <pre><code>&lt;xsl:template match="/"&gt; &lt;xsl:variable name="var"&gt; &lt;xsl:call-template name="age"&gt; &lt;xsl:with-param name="num" select="28" /&gt; &lt;/xsl:call-template&gt; &lt;/xsl:variable&gt; &lt;xsl:value-of select="$var" /&gt; &lt;/xsl:template&gt; &lt;xsl:template name="age"&gt; &lt;xsl:param name="num" /&gt; &lt;xsl:value-of select="concat('You are ', $num, ' years yold!')" /&gt; &lt;/xsl:template&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