Reputation:
I have the following XML given, with a random amount of "Note" elements:
<Notes>
<Note>
<Size>400000</Size>
</Note>
<Note>
<Size>200000</Size>
</Note>
<Note>
<Size>500000</Size>
</Note>
</Notes>
I want to check, if one of these Notes have a size element equal or greater to 500000. If that's the case, I want to call the main template. If not, I want to do something else.
The issue I have is: If I have the if-then logic inside the for-each loop, then I would call the template multiple times. As there is no break-functionality in xslt, I was then thinking to use a variable which I would set to true if the condition is met, and afther the for-each I'd call the template if it was set to true. But this isn't the best approach really I fear, what do you think?
Thanks in advance.
Upvotes: 2
Views: 194
Reputation: 2125
No need for a for-each loop. Something like this will do what you want:
<xsl:template match="Notes">
<xsl:choose>
<xsl:when test="number(descendant::Size/text()) > 500000">
<xsl:call-template name="process Note"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="add attribute to Note"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Upvotes: 2