繁体   English   中英

XSLT使用XSLT从xml删除一个元素的所有属性

[英]XSLT Remove all attribute for one element from xml using XSLT

我有一个大XML文件的以下根元素:

<Interchange xmlns='http://www.e2b.no/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'   
xsi:schemaLocation='http://www.e2b.no/XMLSchema Interchange'>

我需要得到

<Interchange>

请指教。 这是一个最小的文档,其中包含我正在尝试的模板(我尝试的模板不多,因为它们的使用时间更长):

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

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="Interchange/@xmlns|@xmlns:xsi|@xsi:schemaLocation"/>
</xsl:stylesheet>

命名空间声明与属性不同。 这就是为什么您不能像尝试那样将它们从身份模板中排除的原因。

相反,只需匹配元素并输出另一个不带有上述名称空间的“负担”的Interchange

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

确保同时在XSLT样式表中定义所需的名称空间:

xmlns:eb='http://www.e2b.no/XMLSchema'

使用哪个前缀(在这种情况下为eb )是无关紧要的。 但这可以确保找到Interchange元素。 这是至关重要的,因为<Interchange><Interchange xmlns='http://www.e2b.no/XMLSchema'>不同的元素。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM