[英]XSLT remove xml attributes and empty nodes
我有 xml 如下
我想使用 xslt 将其转换为 XML 并删除空节点和一个具有如下属性的节点。
<ROOT>
<a>this is a </a>
<b />
<c> this is c</c>
<d></d>
<e CSK:nil=“true” xmlIns:xsi=“http://www.w3.org/2001/XMLSxhema-instance” />
<ROOT>
我想用 xslt 将其转换为如下所示
<ROOT>
<a>this is a </a>
<c> this is c</c>
<ROOT>
删除空节点或具有属性且为空的节点
<!-- Remove nodes with attributes. -->
<xsl:template match="*[boolean(@*)]"/>
<!-- Remove nodes that are empty or have only spaces. -->
<xsl:template match="*[normalize-space(.) = '']"/>
<!-- Keep everything else. -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.