【问题标题】:Reproduce all attributes in XML conversion using XSLT使用 XSLT 重现 XML 转换中的所有属性
【发布时间】:2011-12-01 19:29:12
【问题描述】:

我尝试使用 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>
...

关于复制所有单元格属性的任何想法?

【问题讨论】:

    标签: html xml xslt xpath


    【解决方案1】:

    用途:

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-13
      • 1970-01-01
      • 2012-08-24
      • 1970-01-01
      • 2018-09-22
      • 1970-01-01
      • 2019-09-26
      相关资源
      最近更新 更多