[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Check if next tag is ...
Anne Kootstra wrote:
The XML file I work with contains records that most of the time have three unique nodes. However, it is part of the design that one of these nodes, T in the example, is optional. Here is an example of a file. In case of "one of these nodes", the former solution might have helped you enough. However, if any number of nodes can become empty, but you do know up front the names of the nodes, you can use the following solution, which works with any combination of (multiple) empty nodes. As long as you know the names and as long as you don't need very many columns, you can use this solution. You were talking of using following-sibling. This might've looked like a viable solution, however, you'd have to make a template for each scenario (missing T, missing S, missing S and T etc), which might not be what you're after. <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/A"> <table> <xsl:apply-templates select="C" /> </table> </xsl:template> <xsl:template match="C"> <tr> <xsl:call-template name="row"> <xsl:with-param name="p" select="P" /> <xsl:with-param name="t" select="T" /> <xsl:with-param name="s" select="S" /> </xsl:call-template> </tr> </xsl:template> <xsl:template name="row"> <xsl:param name="p" /> <xsl:param name="s" /> <xsl:param name="t" /> <xsl:call-template name="cell" > <xsl:with-param name="value" select="$p" /> </xsl:call-template> <xsl:call-template name="cell" > <xsl:with-param name="value" select="$s" /> </xsl:call-template> <xsl:call-template name="cell" > <xsl:with-param name="value" select="$t" /> </xsl:call-template> </xsl:template> <xsl:template name="cell"> <xsl:param name="value" /> <td> <xsl:choose> <xsl:when test="$value"> <xsl:value-of select="$value"/> </xsl:when> <xsl:otherwise>*</xsl:otherwise> </xsl:choose> </td> </xsl:template> </xsl:stylesheet> Cheers, Abel Braaksma
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|