[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Re: HTML table colspec and spanspec problem
Siddhi, This xsl will get close. Needs more work on picking the right alignment based on count. XSL NEW TEMPLATE ADDED AT THE TOP Terry <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:template match="table"> <xsl:result-document href="output.xml"> <table> <tgroup> <xsl:for-each-group select="tbody/tr/td" group-by="."> <!-- FIRST GROUP BY COLUMN NAME --> <xsl:choose> <!-- PICK WHICH TYPE OF SPEC --> <xsl:when test="contains(. , 'and')"> <spanspec> <xsl:attribute name="name"> <xsl:value-of select="substring-before(current-group()[1] , ' and ')"/> <xsl:text>to</xsl:text> <xsl:value-of select="substring-after(current-group()[1] , ' and ')"/> </xsl:attribute> <xsl:attribute name="width"/> <xsl:attribute name="align" select="current-group()[1]/@align"/> <xsl:attribute name="namestart" select="substring-before(current-group()[1] , ' and ')"/> <xsl:attribute name="nameend" select="substring-after(current-group()[1] , ' and ')"/> </spanspec> </xsl:when> <xsl:otherwise> <colspec> <xsl:attribute name="name"> <xsl:value-of select="current-grouping-key()"/> </xsl:attribute> <xsl:attribute name="width"/> <xsl:attribute name="align" select="current-group()[1]/@align"/> </colspec> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> <xsl:apply-templates/> </tgroup> </table> </xsl:result-document> </xsl:template> <xsl:template match="tbody"> <xsl:apply-templates/> </xsl:template> <xsl:template match="tr" mode="abc"> <xsl:if test="preceding::tr[1][child::td[@class='tch']]"> <row> <xsl:apply-templates/> </row> <xsl:apply-templates select="following::tr[1][child::td[@class='tch']]" mode="abc"/> </xsl:if> </xsl:template> <xsl:template match="tr" mode="def"> <xsl:if test="preceding::tr[1][child::td[@class='tbtm']]"> <row> <xsl:apply-templates/> </row> <xsl:apply-templates select="following::tr[1][child::td[@class='tbtm']]" mode="def"/> </xsl:if> </xsl:template> <xsl:template match="tr" mode="xyz"> <xsl:if test="preceding::tr[1][child::td[@class='tb']]"> <row> <xsl:apply-templates/> </row> <xsl:apply-templates select="following::tr[1][child::td[@class='tb']]" mode="xyz"/> </xsl:if> </xsl:template> <xsl:template match="tr"> <xsl:if test="child::td[@class='tch'][not(preceding::tr[1][child::td[@class='tch']])] "> <thead> <row> <xsl:apply-templates/> </row> <xsl:if test="following::*[1][self::tr[child::td[@class='tch']]]"> <xsl:apply-templates select="following::tr[1][child::td[@class='tch']]" mode="abc"/> </xsl:if> </thead> </xsl:if> <xsl:if test="child::td[@class='tbtm'][not(preceding::tr[1][child::td[@class='tbtm']] )]"> <tfoot> <row> <xsl:apply-templates/> </row> <xsl:if test="following::*[1][self::tr[child::td[@class='tbtm']]]"> <xsl:apply-templates select="following::tr[1][child::td[@class='tbtm']]" mode="def"/> </xsl:if> </tfoot> </xsl:if> <xsl:if test="child::td[@class='tb'][not(preceding::tr[1][child::td[@class='tb']])]"> <tbody> <row> <xsl:apply-templates/> </row> <xsl:if test="following::*[1][self::tr[child::td[@class='tb']]]"> <xsl:apply-templates select="following::tr[1][child::td[@class='tb']]" mode="xyz"/> </xsl:if> </tbody> </xsl:if> </xsl:template> <xsl:template match="td"> <entry> <xsl:attribute name="class"> <xsl:value-of select="@class"/> </xsl:attribute> <xsl:if test="@colspan"> <xsl:attribute name="colspan"> <xsl:value-of select="@colspan"/> </xsl:attribute> </xsl:if> <xsl:attribute name="name"> <xsl:text>col</xsl:text> <xsl:if test="not(@colspan)"> <xsl:if test="not(preceding-sibling::td[@colspan])"> <xsl:value-of select="count(preceding-sibling::td)+1"/> </xsl:if> <xsl:if test="preceding-sibling::td[@colspan]"> <xsl:variable name="colspan_values" select="sum(preceding-sibling::td[@colspan]/@colspan)"/> <xsl:variable name="td_number" select="count(preceding-sibling::td)"/> <xsl:variable name="colspan_td_number" select="count(preceding-sibling::td[@colspan])"/> <xsl:value-of select="($td_number+$colspan_values+1) - $colspan_td_number"/> </xsl:if> </xsl:if> <xsl:if test="@colspan"> <xsl:if test="not(preceding-sibling::td[@colspan])"> <xsl:value-of select="count(preceding-sibling::td)+1"/> <xsl:text>to</xsl:text> <xsl:variable name="td_number" select="count(preceding-sibling::td)"/> <xsl:variable name="colspan" select="@colspan"/> <xsl:value-of select="count(preceding-sibling::td)+@colspan"/> </xsl:if> <xsl:if test="preceding-sibling::td[@colspan]"> <xsl:variable name="colspan_values" select="sum(preceding-sibling::td[@colspan]/@colspan)"/> <xsl:variable name="td_number" select="count(preceding-sibling::td)"/> <xsl:variable name="colspan_number" select="count(preceding-sibling::td[@colspan])"/> <xsl:variable name="starting_value"> <xsl:value-of select="($td_number+$colspan_values+1) - $colspan_number"/> </xsl:variable> <xsl:value-of select="$starting_value"/> <xsl:text>to</xsl:text> <xsl:value-of select="($starting_value+@colspan) - 1"/> </xsl:if> </xsl:if> </xsl:attribute> <xsl:apply-templates/> </entry> </xsl:template> <xsl:template match="p"> <p> <xsl:apply-templates/> </p> </xsl:template> </xsl:stylesheet> --~--
|
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
|