Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One way to do this, is to create a sort of 'look-up' table of values. This could be embedded in the XSLT, or put in a separate file. For example, if you put it in the XSLT file, it would look something like this..</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:lookup="lookup"&gt; &lt;lookup:data&gt; &lt;status code="1"&gt;TO DO&lt;/status&gt; &lt;status code="2"&gt;IN PROGRESS&lt;/status&gt; &lt;status code="3"&gt;DONE&lt;/status&gt; &lt;/lookup:data&gt; </code></pre> <p>Then, you would also create a variable to access this data</p> <pre><code>&lt;xsl:variable name="lookup" select="document('')/*/lookup:data"/&gt; </code></pre> <p>Finally, to look up the value, you would simply do this</p> <pre><code>&lt;xsl:value-of select="$lookup/status[@code = '1']/&gt; </code></pre> <p>Here is the full XSLT in this case</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:lookup="lookup"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;lookup:data&gt; &lt;status code="1"&gt;TO DO&lt;/status&gt; &lt;status code="2"&gt;IN PROGRESS&lt;/status&gt; &lt;status code="3"&gt;DONE&lt;/status&gt; &lt;/lookup:data&gt; &lt;xsl:variable name="lookup" select="document('')/*/lookup:data"/&gt; &lt;xsl:template match="status/text()"&gt; &lt;xsl:value-of select="$lookup/status[@code = current()]" /&gt; &lt;/xsl:template&gt; &lt;xsl:template match="@*|node()"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*|node()"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>When applied to your sample XML, the following is output</p> <pre><code>&lt;root&gt; &lt;status&gt;TODO&lt;/status&gt; &lt;/root&gt; </code></pre> <p>It could be better to have these in a separate file though, as then they can be re-used in other stylesheets. To do this, just create a file, called 'lookup.xml', and add the XML </p> <pre><code>&lt;data&gt; &lt;status code="1"&gt;TO DO&lt;/status&gt; &lt;status code="2"&gt;IN PROGRESS&lt;/status&gt; &lt;status code="3"&gt;DONE&lt;/status&gt; &lt;/data&gt; </code></pre> <p>Note, you don't need namespaces in this case. Then just change the definition of the variable to the following</p> <pre><code>&lt;xsl:variable name="lookup" select="document('lookup.xml')/data"/&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. 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.
    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