gpt4 book ai didi

html - 使用 XSLT 重现 XML 转换中的所有属性

转载 作者:数据小太阳 更新时间:2023-10-29 02:31:50 27 4
gpt4 key购买 nike

我尝试使用 XSLT 将 XML 转换为 XHTML。提供的 XML 代码包含表格,其中包含我必须重现的属性:

XML 代码:

...
<table>
<tr>
<td width="70" valign="middle" align="center">
Hi
</td>
<td width="95" valign="middle" align="center">
Ho
</td>
<td width="130" valign="middle" align="center">
Hu
</td>
</tr>
<tr>
<td width="70" valign="middle" align="center" class="text1">
hihihi
</td>
<td width="95" valign="middle" align="right" class="text1">
hohoho
</td>
<td width="130" valign="middle" align="center" class="text1">
huhuhu
</td>
</tr>
</table>
...

现在,我使用该 XSL 代码:

...
<xsl:template match="table">
<table><xsl:apply-templates /></table>
</xsl:template>

<xsl:template match="tr">
<tr><xsl:apply-templates /></tr>
</xsl:template>

<xsl:template match="td">
<td><xsl:apply-templates /></td>
</xsl:template>
...

关于重现所有单元格属性有什么想法吗?

最佳答案

使用:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="table | tr | td">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="@*">
<xsl:copy>
<xsl:apply-templates select="@*"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

关于html - 使用 XSLT 重现 XML 转换中的所有属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8347138/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com