Reputation: 1803
I've got some xml that looks a little like this:
<myGroup>
<something>Stuff</something>
<anotherThing>More Stuff</anotherThing>
<thisThing></thisThing>
<andAnother>Good stuff</andAnother>
<howAboutThis></howAboutThis>
<andOneMore>Tell me the good things</andOneMore>
<lastOne>That come into your mind about your mother</lastOne
<myGroup>
myGroup actually contains more node but I'm only interested in specific one. What I'm trying to do is check if they are empty and display them if not. Like this:
<xsl:if test="something != ''">
<xsl:value-of select="something" />
</xsl:if>
<xsl:if test="anotherThing != ''">
<xsl:value-of select="anotherThing" />
</xsl:if>
etc
What I'm after doing is stop displaying anymore once I have 3 non-empty nodes. Thanks.
Upvotes: 0
Views: 44
Reputation: 167571
Put the condition in a predicate:
<xsl:template match="myGroup">
<xsl:apply-templates select="(something | anotherthing | howAboutThis | lastOne)[normalize-space()][position() < 4]"/>
</xsl:template>
<xsl:template match="myGroup/*">
<xsl:value-of select="."/>
</xsl:template>
Upvotes: 1