Working with Both xsl:if and xsl:choose in XSLT - Other scenarios
(Page 6 of 6 )
In all of the previous examples, we worked with several conditions based on the data. But "xsl:if" is not meant only for conditions. It can also be used to test whether or not there exist any nodes/sub-nodes/leaves etc. under the current node.
For example, the following displays a message if the current "context" has any child elements named "dept no."
<xsl:if test="Deptno">
Got at least one Deptno as child element.
</xsl:if>
And not only that, you can also count the number of child elements using the following code fragment:
<xsl:if test="count(Deptno) = 1">
Got only one Deptno as child element
</xsl:if>
Similarly, if you wanted to work with attribute values rather than text, you can provide attribute names preceded with "@". The following code shows an example:
<xsl:if test="@Sal < '2000')">
Salary is less than 2000 is "1667".
</xsl:if>
In all the above cases, I simply mentioned "xsl:if." The same points apply to "xsl:choose."
I hope you enjoyed the article and any comments, suggestions, feedback, bugs, errors, enhancements etc. are highly appreciated at http://jagchat.spaces.live.com
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |