Reputation: 13
first post so hopefully someone could help out. Basically, I am outputting a pdf via an xslt and my issue is that I have a table that I only want generated if that table contains content. I believe my call-template always initiates and therefore always at least brings back a table header row even if there is no content. I do not want the table to appear at all. Thanks in advance.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:a="http://www.appian.com/ae/types/2009">
<div id="processVariables">
<xsl:call-template name="applicantDetails" />
</div>
<xsl:call-template name="pp" />
<xsl:call-template name="processMilestoneList" />
<xsl:call-template name="processCommentList" />
</div>
<div id="pageFooter" />
</body>
</html>
<xsl:template name="processCommentList">
<div id="processCommentList">
<th space-before ="12pt" keep-with-next="always" font-weight="bold">Process comments:</th>
<table>
<tr>
<th id="date">Date</th>
<th id="user">User</th>
<th id="comment">Comment</th>
</tr>
<xsl:for-each select="//processCommentList/item">
<tr>
<td>
<xsl:call-template name="DisplayDate">
<xsl:with-param name="dateString">
<xsl:value-of select="date"/>
</xsl:with-param>
</xsl:call-template>
</td>
<td>
<xsl:variable name="commentUser">
<xsl:value-of select="user"/>
</xsl:variable>
<xsl:value-of select="//a:processManifest/a:processUserList/a:User[username/@a:id=$commentUser]/fullName/text()"/>
</td>
<td>
<xsl:value-of select="comment" />
</td>
</tr>
</xsl:for-each>
</table>
</div>
Upvotes: 1
Views: 1577
Reputation: 2761
<xsl:if test="//processCommentList/item">
<xsl:call-template name="processCommentList"/>
</xsl:if>
This test will fail if there is no //processCommentList/item and, therefore, not call the template.
If processCommentList is absent if empty, you can also do the more recursive thing of:
<xsl:apply-templates select="//processCommentList"/>
<xsl:template match="processCommentList[count(item)]>
<table>...etc
<xsl:apply-templates select="item"/>
</table> ... etc
</xsl:template>
<xsl:template match="item">
<tr>...etc...</tr>
</xsl:template>
Upvotes: 1