Development and Programming
Use wildcard expressions * and @* to process all XML elements and attributes in XSLT
In XSLT, you can use wildcard expressions such as * and @* to process all the elements and attributes in an XML document. Use of these expressions allows us to apply this stylesheet to any XML document, regardless of the tags it uses. Because we use these wildcard expressions, we have to use the name( ) function to get the name of the element or attribute we’re currently working with.
we can use conditional logic and the expression count(@*) > 0 to determine whether a given element has attributes.
<xsl:if test="count(@*) > 0">
To determine whether the current element has children element or not:
<xsl:if test="count(*) > 0">
Or perhaps you want to check whether the current element has a child named payment or not:
<xsl:when test="count(self::*/payment) > 0">
Alternatively, you could do this
i.e, is there an element in the second position (that saves counting all elements, when you only really want to check there is more than one),
© 2019 Digcode.com. All rights reserved.