我需要使用XSLT 1.0将基于div的XHTML布局转换为基于表格的布局。对于基本的转换,我有一个样式表(见下)创建表结构很好。XSL:读取DIV类属性以创建HTML表格属性
我找不出如何解析输入XHTML上的多个类属性,以便将特定于表的特性添加到输出中。 (是的,我想这些新表的属性,即使类是跨复制)
我的样品XHTML是:
<div class="table align-center">
<div class="tr">
<div class="td"><p>Table Cell 1</p></div>
<div class="td"><p>Table Cell 2</p></div>
</div>
</div>
一个基本的XSL是建立表结构确定,如下:
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="div[contains(@class, 'table')]">
<table>
<xsl:copy-of select="attribute::node()"/>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="div[contains(@class, 'tr')]">
<tr>
<xsl:copy-of select="attribute::node()"/>
<xsl:apply-templates/>
</tr>
</xsl:template>
<xsl:template match="div[contains(@class, 'td')]">
<td>
<xsl:copy-of select="attribute::node()"/>
<xsl:apply-templates/>
</td>
</xsl:template>
这个样式表产生:
<table class="table align-center">
<tr class="tr">
<td class="td"><p>Table Cell 1</p></td>
<td class="td"><p>Table Cell 2</p></td>
</tr>
</table>
我想什么produc e是这样的:
<table class="table align-center" align="center">
<tr class="tr">
<td class="td"><p>Table Cell 1</p></td>
<td class="td"><p>Table Cell 2</p></td>
</tr>
</table>
是否可以用XSLT 1.0来做到这一点?我希望解决方案足够通用,可以添加2个或更多的类并解析它们以添加所需的表属性。
谢谢!
类属性值要求标记化,所以我想知道您是否可以使用http://www.exslt.org/str/functions/tokenize/index.html。你的目标是哪个XSLT 1.0处理器? –
嗨马丁。我使用PHP内置的XSL流程。我相信功能不受支持。 – Kevin