如何使用xsl从xml中删除属性? [英] How to remove attribute from xml using xsl?

查看:83
本文介绍了如何使用xsl从xml中删除属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Team,

       我想从我的xml文件中删除unnessary属性。我知道我们可以通过xsl删除。但我不知道该怎么做。我在互联网上搜索我无法得到期望的结果。

        I want to remove unnessary attribute from my xml file. I know we can remove by xsl. But i don't know how to do it. I search on internet i can't get expect result.

这是我的xml输出

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<rsm:Invoice xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:rsm="http://www.ita.org/" 
xmlns:ccts="urn:un:unece:uncefact:documentation:standard:CoreComponentsTechnicalSpecification:2" 
xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:2" 
xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:2" 
xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:2" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.ita.org/ Invoice_20.xsd">
  <rsm:HeaderExchangedDocument>
    <ram:ID xmlns:ram="http://www.ita.org/">103004</ram:ID>
    <ram:TypeCode xmlns:ram="http://www.ita.org/">Invoice</ram:TypeCode>
    <ram:IssueDateTime xmlns:ram="http://www.ita.org/">2014-01-01</ram:IssueDateTime>
    <ram:CopyIndicator xmlns:ram="http://www.ita.org/">Original</ram:CopyIndicator>
    <ram:CustomsID xmlns:ram="http://www.ita.org/" />
    <ram:HeaderInformation xmlns:ram="http://www.ita.org/" />
    <ram:SummaryInformation xmlns:ram="http://www.ita.org/" />
  </rsm:HeaderExchangedDocument>
  <rsm:SpecifiedLogisticsConsignment>
    <ram:IncludedSupplyChainConsignment xmlns:ram="http://www.ita.org/">
      <ram:BorderCrossingLogisticsTransportMovement>
        <ram:ModeCode>1</ram:ModeCode>
        <ram:Mode>Sea</ram:Mode>
        <ram:ID />
      </ram:BorderCrossingLogisticsTransportMovement>
    </ram:IncludedSupplyChainConsignment>
  </rsm:SpecifiedLogisticsConsignment>
</rsm:Invoice>




我想获得以下格式

<?xml version="1.0" encoding="UTF-8"?>
<rsm:Invoice xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:rsm="http://www.ita.org/" 
xmlns:ccts="urn:un:unece:uncefact:documentation:standard:TechnicalSpecification:2" 
xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:2" 
xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:2" 
xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:2" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.ita.org/ Invoice_20.xsd">
  <rsm:HeaderExchangedDocument>
    <ram:ID>103004</ram:ID>
    <ram:TypeCode>Invoice</ram:TypeCode>
    <ram:IssueDateTime>2014-01-01</ram:IssueDateTime>
    <ram:CopyIndicator>Original</ram:CopyIndicator>
    <ram:CustomsID/>
    <ram:HeaderInformation/>
    <ram:SummaryInformation/>
  </rsm:HeaderExchangedDocument>
  <rsm:SpecifiedLogisticsConsignment>
    <ram:IncludedSupplyChainConsignment>
      <ram:BorderCrossingLogisticsTransportMovement>
        <ram:ModeCode>1</ram:ModeCode>
        <ram:Mode>Sea</ram:Mode>
        <ram:ID />
      </ram:BorderCrossingLogisticsTransportMovement>
    </ram:IncludedSupplyChainConsignment>
  </rsm:SpecifiedLogisticsConsignment>
</rsm:Invoice>

请帮帮我。

最好的问候,

Yukon

Make Simple&轻松

Make Simple & Easy

推荐答案

您要删除的内容不是属性,而是命名空间声明。 

What you are trying to remove are not attributes but rather namespace declarations. 

在您的示例中,删除这些将生成完全不同的XML文档,因为TypeCode(例如)将获得命名空间: 

In your example, removing these will generate a completely different XML document, since TypeCode (for instance) will get Namespace: 

urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:2

而不是: 

instead of: 

http://www.ita.org/

你确定这是什么你想要吗?

Are you sure this is what you want?


这篇关于如何使用xsl从xml中删除属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆