如何解决需要重新调整colspec表项
我需要在cols元素下重新排列表colspec的以下输出
我输入的内容:
<table>
<tgroup>
<colspec colwidth="100pt"/>
<colspec colwidth="100pt"/>
<thead>
<row>
<entry>Claims</entry>
<entry>Claims</entry>
</row>
</thead>
<tbody>
<row>
<entry>Claims</entry>
<entry>Claims</entry>
</row>
</tbody>
</tgroup>
</table>
我正在尝试的XSLT是copy-of
元素:
<xsl:template match="table">
<table>
<cols>
<xsl:copy-of select="colspec"/>
</cols>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="tgroup">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="colspec">
<col><xsl:attribute name="colwidth"><xsl:value-of select="@colwidth"/></xsl:attribute>
<xsl:apply-templates/>
</col>
</xsl:template>
<xsl:template match="thead">
<thead>
<xsl:apply-templates/>
</thead>
</xsl:template>
<xsl:template match="tbody">
<tbody>
<xsl:apply-templates/>
</tbody>
</xsl:template>
<xsl:template match="row">
<tr>
<xsl:apply-templates/>
</tr>
</xsl:template>
<xsl:template match="entry">
<td>
<xsl:apply-templates/>
</td>
</xsl:template>
预期输出为:
<table>
<cols>
<col colwidth="100pt"/>
<col colwidth="100pt"/>
</cols>
<thead>
<tr>
<td>Claims</td>
<td>Claims</td>
</tr>
</thead>
<tbody>
<tr>
<td>Claims</td>
<td>Claims</td>
</tr>
</tbody>
</table>
我需要将colspec
元素置于cols
元素之下。我尝试了copy-of
方法。但是我无法获取cols
解决方法
怎么样:
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/table">
<xsl:copy>
<cols>
<xsl:apply-templates select="tgroup/colspec"/>
</cols>
<xsl:apply-templates select="tgroup/(thead | tbody)"/>
</xsl:copy>
</xsl:template>
<xsl:template match="colspec">
<col colwidth="{@colwidth}"/>
</xsl:template>
<xsl:template match="thead | tbody">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="row">
<tr>
<xsl:apply-templates/>
</tr>
</xsl:template>
<xsl:template match="entry">
<td>
<xsl:apply-templates/>
</td>
</xsl:template>
</xsl:stylesheet>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。