I’m trying to insert an if-else statement inside of a foreach statement in XSLT.
The idea is , if the node exist it will insert a line break.This is what I have so far
<xsl:for-each select="Books/Publisher/[BookTitle]">
<strong>
<xsl:value-of select=" BookTitle " />
</strong>
<xsl:if test=" Books/Publisher/BookTitle">!= ''">
<br/>
</xsl:if>
</xsl:for-each>
The problem is that the line break tag does not appear when I insert an if-else statement but will only work when I remove the if else entirely.Can someone explain to me why this is happening,because I’ve checked the node is there and inserting the linebreak should work.So there must be something wrong with the if-else inside the foreach loop.
I think what you are going for is this:
But if I understand correctly, it looks like all you’re really trying to do is output all the non-blank book titles, followed by line breaks, so perhaps this would be a better approach:
Or better yet: