【问题标题】:Copy element with attributes but without child elements复制具有属性但没有子元素的元素
【发布时间】:2019-02-26 18:59:12
【问题描述】:

用下面的xml文档

<?xml version="1.0" encoding="UTF-8"?>

<a name="john">
   <b/>
</a>

和下面的xslt

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="a">
        <xsl:copy/>
    </xsl:template>

</xsl:stylesheet>

输出是

<?xml version="1.0" encoding="UTF-8"?><a/>

我想要的是&lt;a name="John"/&gt;。如何获取元素 a 及其属性 name 没有其子 b

【问题讨论】:

    标签: xml xslt copy


    【解决方案1】:

    也复制属性:

    <xsl:template match="a">
        <xsl:copy>
          <xsl:copy-of select="@*"/>
        </xsl:copy>
    </xsl:template>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-03
      • 2023-03-23
      • 2014-07-06
      • 1970-01-01
      • 2022-08-23
      • 2015-05-21
      • 1970-01-01
      • 2015-01-08
      相关资源
      最近更新 更多