 |
 |
 |
Hi,
I have written the XSLT below to figure out the number of rows and columns so that I can add the rowspan and colspan to a <TD> element and it seems to be working.
However, I am not sure if this is the best and most effective way to do it in XSLT and would appreciate very much your comments and maybe if there is better approach I would be thankful if you could share it with us.
Please note that I am using XSLT 1.0 and msxml
Given this xml:
1 - the colspan would be 2 (1 ColGrp + 1 Col)
2 - the rowsapn would be 2 (1 RowGrp + 1 Row)
<Report>
<Columns>
<ColGrp heading="Year">
<Col heading="2003"/>
<Col heading="2004"/>
</ColGrp>
<ColGrp heading="">
<Col heading="Total"/>
</ColGrp>
</Columns>
<Rows>
<RowGrp heading="Journal Group Name">
<Row heading="Gastroenterology">
<Cell/>
</Cell>
</Row>
<Row heading="Pharmacy">
<Cell/>
<Cell/>
</Row>
</RowGrp>
<RowGrp heading="">
<Row heading="Totals">
<Cell/>
<Cell/>
</Row>
</RowGrp>
</Rows>
</Report>
I would like to point out that I can have many <ColGrp> elements child of <ColGrp>. Similarly, I may have many <RowGrp> elements. Therefore, I need a dynamic way to count all ColGrp/RowGrp + 1 for the Col/Row
3 - here the colspan would be 4 ( ColGrp + ColGrp + ColGrp + Col)
<Columns>
<ColGrp heading="Test">
<ColGrp heading="Test">
<ColGrp heading="Year">
<Col heading="2003"/>
<Col heading="2004"/>
</ColGrp>
<ColGrp heading="">
<Col heading="Total"/>
</ColGrp>
</ColGrp>
</ColGrp>
</Columns>
+++++
4 - here the rowspan would be 3 (RowGrp + RowGrp + Row)
<Rows>
<RowGrp heading="Media Full Name">
<RowGrp heading="Oncology">
<Row heading="Blood">
<Cell/>
</Row>
<Row heading="Oncology News International">
<Cell/>
</Row>
</RowGrp>
</RowGrp>
<RowGrp>
<RowGrp>
<Row heading="Total">
<Cell/>
</Row>
</RowGrp>
</RowGrp>
</Rows>
As you can see I need to work with only one ColGrp or RowGrp.
This is the extract of the XSLT I am using:
<xsl:variable name="row-span">
<xsl:call-template name="count-row-span">
<xsl:with-param name="set" select="/Report/Columns/ColGrp"/>
<xsl:with-param name="rowcount" select="0"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="col-span">
<xsl:call-template name="count-col-span">
<xsl:with-param name="set" select="/Report/Rows/RowGrp"/>
<xsl:with-param name="colcount" select="1"/>
</xsl:call-template>
</xsl:variable>
<xsl:template name="count-col-span">
<xsl:param name="set"/>
<xsl:param name="colcount"/>
<xsl:choose>
<xsl:when test="$set/RowGrp">
<xsl:call-template name="count-col-span">
<xsl:with-param name="set" select="$set/*[1]"/>
<xsl:with-param name="colcount" select="$colcount + 1"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$set/Row">
<xsl:value-of select ="$colcount + 1"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="count-row-span">
<xsl:param name="set"/>
<xsl:param name="rowcount"/>
<xsl:choose>
<xsl:when test="$set/ColGrp">
<xsl:call-template name="count-row-span">
<xsl:with-param name="set" select="$set/*[1]"/>
<xsl:with-param name="rowcount" select="$rowcount + 1"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$set/Col">
<xsl:value-of select ="count($set[1]/Col) + $rowcount + 2"/>
</xsl:when>
</xsl:choose>
Cheers
C
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@l...>
--~--
|
 | 

|  |
These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.
|  |
| |
 |
 |
 |