[英]XSLT Remove all attribute for one root element from xml using XSLT
I have the following root element of a big XML file: 我有一个大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'>
I need to get 我需要得到
<Interchange>
Please advice, Sorry, I will not give examples of my attempts I will use basic template: 请指教,对不起,我不会提供使用基本模板的尝试示例:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:e2b='http://www.e2b.no/XMLSchema'>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*" />
<!-- copy everything as-is apart from exceptions below -->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="e2b:Interchange">
<Interchange>
<xsl:apply-templates/>
</Interchange>
</xsl:template>
</xsl:stylesheet>
When I tested I accidentally sent big XML to input with the beginning: 当我测试时,我不小心将大的XML输入到开头:
<?xml version='1.0' encoding='ISO-8859-1'?>
<Interchange>
insted 插入
<?xml version='1.0' encoding='ISO-8859-1'?>
<Interchange xmlns='http://www.e2b.no/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://www.e2b.no/XMLSchema Interchange'>
Because I answered positive on my previous question. 因为我对上一个问题的回答是肯定的。
Please advice, any ideas. 请指教,任何想法。
Use 采用
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:e2b='http://www.e2b.no/XMLSchema'
exclude-result-prefixes="e2b">
<!-- copy everything as-is apart from exceptions below -->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="e2b:*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="/e2b:Interchange">
<xsl:element name="{local-name()}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
That approach is necessary to transform the element from the e2b
namespace to no namespace. 该方法对于将元素从e2b
命名空间转换为无命名空间是必需的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.