|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Building tables with optional data elements
Hello Grant,
your XML is not very comfortable. You should remove 'Column' in the Name of every Item/NameValue, because otherwise you have to do a more complex comparison to get the maximum number of columns. <xsl:variable name="maxNoOfColumns" select="Item/NameValue[last()] [not(Name < ../following-sibling::Item/NameValue[last()]/Name)]/Name"/> Here the maximum number of columns are calculated. Every last NameValue/Name of an Item (your NameValue or sorted in an Item) is compared to all following last NameValue/Name and this is one is used, which has no following NameValue/Name with a higher column number. If you don't want to remove 'Column' you have to do it dynamically, what will further slow down the comparison: <xsl:variable name="maxNoOfColumns" select="Item/NameValue[last()] [not(translate(Name, 'Column', '') < translate(../following-sibling::Item/NameValue[last()]/Name, 'Column', ''))]/Name"/> So remove 'Column' from the XML. If it shell be written in the header, it's a styling question and should be handled in the XSL as following. Complete XSL: <xsl:template match="Data">
<xsl:variable name="maxNoOfColumns" select="Item/NameValue[last()]
[not(Name < ../following-sibling::Item/NameValue[last()]/Name)]/Name"/>
<table border="1">
<tr>
<xsl:call-template name="header">
<xsl:with-param name="maxNoOfColumns" select="$maxNoOfColumns"/>
</xsl:call-template>
</tr>
<xsl:apply-templates select="Item">
<xsl:with-param name="maxNoOfColumns" select="$maxNoOfColumns"/>
</xsl:apply-templates>
</table>
</xsl:template><xsl:template match="Item">
<xsl:param name="maxNoOfColumns" select="0"/>
<tr>
<xsl:call-template name="row">
<xsl:with-param name="maxNoOfColumns" select="$maxNoOfColumns"/>
</xsl:call-template>
</tr>
</xsl:template><xsl:template name="header">
<xsl:param name="maxNoOfColumns" select="0"/>
<xsl:param name="currentNo" select="1"/>
<xsl:if test="$currentNo < $maxNoOfColumns + 1">
<td>Column<xsl:value-of select="$currentNo"/></td>
<xsl:call-template name="header">
<xsl:with-param name="maxNoOfColumns" select="$maxNoOfColumns"/>
<xsl:with-param name="currentNo" select="$currentNo + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template><xsl:template name="row"> <xsl:param name="maxNoOfColumns" select="0"/> <xsl:param name="currentNo" select="1"/> <xsl:if test="$currentNo < $maxNoOfColumns + 1"> <td> <xsl:value-of select="NameValue[Name = $currentNo]/Value"/> <xsl:if test="not(normalize-space(NameValue[Name = $currentNo]/Value))"> </xsl:if> </td> <xsl:call-template name="row"> <xsl:with-param name="maxNoOfColumns" select="$maxNoOfColumns"/> <xsl:with-param name="currentNo" select="$currentNo + 1"/> </xsl:call-template> </xsl:if> </xsl:template> Regards, Joerg Grant Thiselton wrote: Good Day, XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|

Cart








