需要重新对齐 colspec table 项目
Need to realign the colspec table item
我需要在 cols 元素下重新对齐 table 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>
我需要在 cols 元素下重新对齐 table 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>