Jump to content

XSL choose when test


Guest bval

Recommended Posts

I need a way to apply a template if the node exists but if it does not exist, I want it to put in static code. There is no exists in XSL, so I do not know how to make it do this. (There may be multiple headers as well, meaning I may have a Sheader4 & a Sheader 5.) Please advise me if you have any idea how to do this. The following was my attempt at accomplishing this: <xsl:apply-templates select="SHeader1 |SHeader2 |SHeader3 |SHeader4 |SHeader5"/> <xsl:choose> <xsl:when test="exists(SHeader1 |SHeader2 |SHeader3 |SHeader5|SHeader4)"> <xsl:apply-templates select="(SHeader1 |SHeader2 |SHeader3 |SHeader5 |SHeader4)"/> </xsl:when> <xsl:otherwise> <tr> <td align="center" vAlign="top" class="title"> <font size="1" face="arial">ACCT</font> </td> <td align="center" vAlign="top" class="title"> <font size="1" face="arial">NEW <br/>BALANCE </font> </td> <td align="center" vAlign="top" class="title"> <font size="1" face="arial">DIVIDENDS <br/>YTD </font> </td> <td align="center" vAlign="top" class="title"> <font size="1" face="arial">TAX <br/>NAME </font> </td> <td align="center" vAlign="top" class="title"> <font size="1" face="arial">LOAN</font> </td> <td align="center" vAlign="top" class="title"> <font size="1" face="arial">NEW <br/>BALANCE </font> </td> <td align="center" vAlign="top" class="title"> <font size="1" face="arial">FINANCE <br/>CHARGE YTD </font> </td> <td> </td> </tr> </xsl:otherwise> </xsl:choose><xsl:template match="SHeader5 |SHeader4 |SHeader1 |SHeader2 |SHeader3"> <tr> <td class="title"><xsl:value-of select="COL1"/></td> <td class="title"><xsl:value-of select="COL2"/></td> <td class="title"><xsl:value-of select="COL3"/></td> <td class="title"><xsl:value-of select="COL4"/></td> <td class="title"><xsl:value-of select="COL5"/></td> <td class="title"><xsl:value-of select="COL6"/></td> <td class="title"><xsl:value-of select="COL7"/></td> <td class="title"><xsl:value-of select="COL8"/></td> </tr></xsl:template>Thanks!

Link to comment
Share on other sites

If you select a node, there will only be a result if the node exist. It's otherwise returning false. So you could simply use

<xsl:choose><xsl:when test="SHeader1|SHeader2|SHeader3|SHeader5|SHeader4"><xsl:apply-templates select="SHeader1|SHeader2|SHeader3|SHeader5|SHeader4"/></xsl:when><xsl:otherwise><tr> <td align="center" vAlign="top" class="title"><font size="1" face="arial">ACCT</font></td><td align="center" vAlign="top" class="title"><font size="1" face="arial">NEW <br/>BALANCE </font></td><td align="center" vAlign="top" class="title"><font size="1" face="arial">DIVIDENDS <br/>YTD </font></td><td align="center" vAlign="top" class="title"><font size="1" face="arial">TAX <br/>NAME </font></td><td align="center" vAlign="top" class="title"><font size="1" face="arial">LOAN</font></td><td align="center" vAlign="top" class="title"><font size="1" face="arial">NEW <br/>BALANCE </font></td><td align="center" vAlign="top" class="title"><font size="1" face="arial">FINANCE <br/>CHARGE YTD </font></td><td>  </td></tr></xsl:otherwise></xsl:choose>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...