0

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

这是当前我的 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>

我可以在 xslt 中做什么?

4

1 回答 1

0

好吧,ram:ID 正在作为命名空间“http://www.ita.org/”中的一个元素输出,您希望它作为命名空间“urn:un:unece:uncefact:data:standard:”中的一个元素: ReusableAggregateBusinessInformationEntity:2"

因此,无论生成什么代码,都将其置于错误的命名空间中,需要修复;你还没有显示你的代码,所以我们不能告诉你哪里错了。

用谷歌搜索答案的麻烦在于,如果你不理解所用语言的概念,你会用谷歌搜索错误的东西。您的问题不是删除属性,而是更正元素名称。暂时忘记 google,也忘记编码,而是阅读一本关于 XSLT 的好书。

于 2012-11-02T13:24:26.110 回答