Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - XSL table problems [Thread Next] RE: XSL table problemsTo: NULL Date: 1/8/2007 3:05:00 AM
Sorry, for the delay. Here's an example, if you're still interested:
<?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" version="1.0" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:apply-templates select="table"/>
</xsl:template>
<!-- Matched templates -->
<!-- table -->
<xsl:template match="table">
<xsl:copy>
<xsl:apply-templates select="row"/>
</xsl:copy>
</xsl:template>
<!-- row -->
<xsl:template match="row">
<tr>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="cell"/>
</tr>
</xsl:template>
<!-- cell -->
<xsl:template match="cell">
<xsl:if test="not(contains(., 'rowspan')) and not(contains(., 'colspan'))">
<xsl:variable name="pos" select="position()"/>
<xsl:variable name="colspan">
<xsl:value-of select="parent::row/cell[position() = ($pos -
1)][contains(., 'colspan')]"/>
</xsl:variable>
<xsl:variable name="rowspan">
<xsl:value-of select="parent::row/cell[position() = ($pos -
1)][contains(., 'rowspan')]"/>
</xsl:variable>
<xsl:variable name="isHead">
<xsl:choose>
<xsl:when test="parent::row/@style or position() = 1">
<xsl:value-of select="'th'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'td'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:element name="{$isHead}">
<xsl:if test="not(@colspan) and not(@rowspan)">
<xsl:if test="$colspan != ''">
<xsl:attribute name="colspan">
<xsl:value-of select="number(translate(substring-after($colspan,
'='), ' "', ''))"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$rowspan != ''">
<xsl:attribute name="rowspan">
<xsl:value-of select="number(translate(substring-after($rowspan,
'='), ' "', ''))"/>
</xsl:attribute>
</xsl:if>
</xsl:if>
<xsl:if test="position() = 1">
<xsl:attribute name="style">
<xsl:value-of select="'text-align: left;'"/>
</xsl:attribute>
</xsl:if>
<xsl:copy-of select="text() | * | @*"/>
</xsl:element>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
ML
---
http://milambda.blogspot.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
