如何只获取部分xml文档并同时删除命名空间? [英] How can I get just part of the xml document and remove namespaces at the same time?
问题描述
我有以下xml文档。 我想要一个新的xml文档,我只想要位置信息,我想删除命名空间。我还包括了一个xls,我已经反复修改但无法得到我需要的结果。 我感谢
我可以得到任何帮助吗?
I have the following xml document. I want a new xml document and I only want the location information and I want to remove the namespacing. I have also included an xls that I have modified over and over but cannot get the results I need. I appreciate any help i can get?
my xsl:
推荐答案
这应删除两个名称空间:
This should remove the two namespaces:
<?xml version =" 1.0" encoding =" utf-16"?>
< xsl:stylesheet version =" 1.0"的xmlns:XSL = QUOT; HTTP://www.w3.org/1999/XSL/Transform" xmlns:n1 =" gary">
< xsl:output method =" xml"版本= QUOT; 1.0"编码= QUOT; UTF-8英寸/>
< xsl:template match =" /">
&NBSP; < NewStuff>
&NBSP; &NBSP; < xsl:apply-templates select =" stuff" />
&NBSP; < / NewStuff>
< / xsl:template>
< xsl:template match =" stuff">
&NBSP; < xsl:apply-templates />
< / xsl:template>
< xsl:template match =" * [namespace-uri()='gary']">
&NBSP; < xsl:element name =" {name()}" namespace ="">
&NBSP; &NBSP; < xsl:apply-templates />
&NBSP; < / xsl:element>
< / xsl:template>
< xsl:template match =" * [namespace-uri()='troy']">
&NBSP; < xsl:element name =" {name()}" namespace ="">
&NBSP; &NBSP; < xsl:apply-templates />
&NBSP; < / xsl:element>
< / xsl:template>
< xsl:template match =" @ * | node()">
&NBSP; < xsl:copy>
&NBSP; &NBSP; < xsl:apply-templates select =" @ * | node()" />
&NBSP; < / xsl:copy>
< / xsl:template>
< / xsl:stylesheet>
<?xml version="1.0" encoding="utf-16"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:n1="gary">
<xsl:output method="xml" version="1.0" encoding="UTF-8" />
<xsl:template match="/">
<NewStuff>
<xsl:apply-templates select="stuff" />
</NewStuff>
</xsl:template>
<xsl:template match="stuff">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="*[namespace-uri() = 'gary']">
<xsl:element name="{name()}" namespace="">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="*[namespace-uri() = 'troy']">
<xsl:element name="{name()}" namespace="">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Morten la Cour
Morten la Cour
这篇关于如何只获取部分xml文档并同时删除命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!