Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To your questions:</p> <blockquote> <p>Is there any way to break the statement in for-each if condition is true ?</p> </blockquote> <p>No, and normally this is also unnecessary. XSLT is not an imperative programming language, and imperative approaches do not really work well here.</p> <p>What you seemingly want to do is expressing "find the first <code>&lt;LeafNode&gt;</code> where <code>@Type='ABC'</code>, and return true or false depending on whether there is one.</p> <p>The way to do this in traditional languages is like your approach: for each node, check condition, if condition satisfied then return.</p> <p>In XSLT you simply select the node with XPath:</p> <pre><code>//RootNode/LeafNode[@Type='ABC'] </code></pre> <p>either the result of this contains a node, or it does not. No need for a for-each at all.</p> <blockquote> <p>Can we use the value of Template variable or param from main calling routine ?</p> </blockquote> <p>No. Variables and params are strictly scoped. They go out of scope once processing leaves their parent element. They are also constant, once declared they cannot be changed.</p> <p>The way to do what you want here is making the template <em>output</em> the desired value and capture it in a variable:</p> <pre><code>&lt;xsl:template&gt; &lt;xsl:variable name="returnValue"&gt; &lt;xsl:call-template name="TestTemplate" /&gt; &lt;/xsl:variable&gt; &lt;/xsl:template&gt; &lt;xsl:template name="TestTemplate"&gt; &lt;!-- the following expression emits true or false --&gt; &lt;xsl:value-of select=" count(//RootNode/LeafNode[@Type='ABC']) gt; 0 " /&gt; &lt;/xsl:template&gt; </code></pre> <p>Two last hints: </p> <ul> <li>avoid the <code>'//'</code> operator at all costs. Most of the time its use is not necessary</li> <li>the first, top-most element in a document is not the "root node", it is the "document element"</li> </ul> <p>This is an important distinction. The "root node" comes <em>before</em> the document element, so the XPath above should be more like this (semantically):</p> <pre><code>/DocumentElement/LeafNode ^------ *this* slash represents the "root node" </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