Note that there are some explanatory texts on larger screens.

plurals
  1. POXSL: selecting data from a node based on the value of a variable
    text
    copied!<p>I'm working on a minor project learning XSL, and I've run across a problem...</p> <p>I have a Docbook file with a series of entires for people categorized by Department. Occasionally, however, I will have a person who works in a minor group as well as his own. To avoid duplication of data, I specified that a person node either contains the data in their node, or an xref node that links to their main node. When I iterate over all people in a group, I need to check whether the node is a linked node or a data node and adjust my variables accordingly.</p> <p>Here's the choose code</p> <pre><code>&lt;xsl:choose&gt; &lt;xsl:when test="xref"&gt; &lt;xsl:variable name="TAG_ID" select="xref/@linkend" /&gt; &lt;xsl:variable name="NAME" select="//*[@id='$TAG_ID']/para[@id='who']" /&gt; &lt;xsl:variable name="EMAIL" select="//*[@id='$TAG_ID']/para[@id='who']/ulink/@url" /&gt; &lt;xsl:variable name="IMAGE" select="//*[@id='$TAG_ID']/para[@id='image']" /&gt; &lt;xsl:variable name="MEET" select="//*[@id='$TAG_ID']/para[@id='meet']" /&gt; &lt;xsl:call-template name="output_person" /&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:variable name="NAME" select="para[@id ='who']" /&gt; &lt;xsl:variable name="EMAIL" select="para[@id='who']/ulink/@url" /&gt; &lt;xsl:variable name="IMAGE" select="para [@id='image']" /&gt; &lt;xsl:variable name="MEET" select="para [@id='meet']" /&gt; &lt;xsl:call-template name="output_person" /&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; </code></pre> <p>However, when I try to run this I get the following errors...</p> <pre><code>runtime error: file team.xsl line 92 element img Variable 'IMAGE' has not been declared. xmlXPathCompiledEval: evaluation failed </code></pre> <p>After some looking on the internet, I have simultaneously seen code that accomplishes this and people saying its impossible.</p> <p>So my question is twofold...</p> <p>Can I select a specific node based on an variable?</p> <p>and if not, can this even be done? </p>
 

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