xml - XSL - How to do one thing if node has child, otherwise do another -
i'm farely new xslt , have tried various method check whether node has child. have following:
<xsl:if test="child::list">
the above part works, problem have tried using when
in method otherwise
, not work. looked so:
<xsl:when test="child::list">
which i'm guessing wrong doesn't work.
the code below:
<xsl:for-each select="td"> <td> <xsl:when test="child::list"> <table cellpadding='0' cellspacing='0'> <thead> <tr> <xsl:for-each select="list/item/table/thead/tr/th"> <th><xsl:value-of select="self::node()[text()]"/></th> </xsl:for-each> </tr> <xsl:for-each select="list/item/table/tbody/tr"> <tr> <xsl:for-each select="td"> <td><xsl:value-of select="self::node()[text()]"/></td> </xsl:for-each> </tr> </xsl:for-each> </thead> </table> </xsl:when> <xsl:otherwise> <xsl:value-of select="self::node()[text()]"/> </xsl:otherwise> </td> </xsl:for-each>
any appreciated...
xsl:when
, xsl:otherwise
have inside of xsl:choose
:
<xsl:choose> <xsl:when test="..."> <!-- 1 thing --> </xsl:when> <xsl:otherwise> <!-- else --> </xsl:otherwise> </xsl:choose>
but should here utilize templates:
<xsl:template match="something"> .... <xsl:apply-templates select="td" mode="list" /> .... </xsl:template> <xsl:template match="td" mode="list"> <xsl:value-of select="."/> </xsl:template> <xsl:template match="td[list]" mode="list"> <table cellpadding='0' cellspacing='0'> <thead> <xsl:apply-templates select='list/item/table/thead/tr' /> <xsl:apply-templates select="list/item/table/tbody/tr" /> </thead> </table> </xsl:template> <xsl:template match="th | td"> <xsl:copy> <xsl:value-of select="." /> </xsl:copy> </xsl:template> <xsl:template match="tr"> <xsl:copy> <xsl:apply-templates select="th | td" /> </xsl:copy> </xsl:template>