1

我需要删除信封 sh:StandardBusinessDocument、sh:StandardBusinessDocumentHeader 和 ObjectEnvelope 保持发票完好无损。

<?xml version="1.0" encoding="ISO-8859-1"?>
<sh:StandardBusinessDocument xmlns:sh="urn:sfti:documents:StandardBusinessDocumentHeader" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<sh:StandardBusinessDocumentHeader>
<sh:HeaderVersion>1.0</sh:HeaderVersion>
<sh:Sender>
<sh:Identifier Authority="countrycode:organizationid">3465560211475</sh:Identifier>
</sh:Sender>
<sh:Receiver>
<sh:Identifier Authority="countrycode:organizationid">5620452103</sh:Identifier>
</sh:Receiver>
<sh:DocumentIdentification>
<sh:Standard>urn:sfti:documents:BasicInvoice:1:0</sh:Standard>
<sh:TypeVersion>1.0</sh:TypeVersion>
<sh:InstanceIdentifier>0511323816</sh:InstanceIdentifier>
<sh:Type>BasicInvoice</sh:Type>
<sh:MultipleType>true</sh:MultipleType>
<sh:CreationDateAndTime>2017-01-04T05:48:14</sh:CreationDateAndTime>
</sh:DocumentIdentification>
</sh:StandardBusinessDocumentHeader>
<Invoice xmlns="urn:sfti:documents:BasicInvoice:1:0" xmlns:cac="urn:sfti:CommonAggregateComponents:1:0" xmlns:cbc="urn:oasis:names:tc:ubl:CommonBasicComponents:1:0" xmlns:ccts="urn:oasis:names:tc:ubl:CoreComponentParameters:1:0" xmlns:cur="urn:oasis:names:tc:ubl:codelist:CurrencyCode:1:0" xmlns:sdt="urn:oasis:names:tc:ubl:SpecializedDatatypes:1:0" xmlns:udt="urn:oasis:names:tc:ubl:UnspecializedDatatypes:1:0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ID>2522987548</ID>
  <cbc:IssueDate>2017-01-01</cbc:IssueDate>
  <InvoiceTypeCode>380</InvoiceTypeCode>
  <cbc:Note>Vid frågor gällande resedebiteringar, kontakta din lokala resebyrå. Övrigt, kontakta Kundservice.</cbc:Note>
  <InvoiceCurrencyCode>SEK</InvoiceCurrencyCode>
  <LineItemCountNumeric>4</LineItemCountNumeric>
  <AdditionalDocumentReference>
    <cac:ID identificationSchemeID="CT">197911</cac:ID>
  </AdditionalDocumentReference>
  <AdditionalDocumentReference>
    <cac:ID identificationSchemeID="ACD">197911</cac:ID>
  </AdditionalDocumentReference>
  <cac:BuyerParty>
    <cac:Party>
      <cac:PartyIdentification>
        <cac:ID identificationSchemeID="92">5560452103</cac:ID>
      </cac:PartyIdentification>
      <cac:PartyName>
        <TwoHundreedMoreFields>...</TwoHundreedMoreFields>
      </cac:PartyName>
    </cac:Party>
  </cac:BuyerParty>
  <cac:SellerParty>
    <cac:Party>
      <cac:PartyIdentification>
        <cac:ID identificationSchemeID="91">5164060120</cac:ID>
      </cac:PartyIdentification>
      <cac:PartyName>
        <TwoHundreedMoreFields>...</TwoHundreedMoreFields>
      </cac:PartyName>
    </cac:Party>
  </cac:SellerParty>
  <cac:InvoiceLine>
    <cac:ID>31</cac:ID>
    <cbc:InvoicedQuantity quantityUnitCode="">1.00</cbc:InvoicedQuantity>
    <cbc:LineExtensionAmount amountCurrencyID="SEK">340.00</cbc:LineExtensionAmount>
    <cbc:Note>ARLANDA PARKERING  STHLM ARLANDA  Netto: 340,00  Moms: 0,00  Brutto: 340,00</cbc:Note>
  </cac:InvoiceLine>
  <cac:InvoiceLine>
    <cac:ID>32</cac:ID>
    <cbc:InvoicedQuantity quantityUnitCode="">1.00</cbc:InvoicedQuantity>
    <cbc:LineExtensionAmount amountCurrencyID="SEK">2273.00</cbc:LineExtensionAmount>
    <cbc:Note>Something AB  Bromma  Netto: 2273,00  Moms: 0,00  Brutto: 2273,00</cbc:Note>
  </cac:InvoiceLine>
</Invoice>
<ObjectEnvelope xmlns:cac="urn:sfti:CommonAggregateComponents:1:0" xmlns:cbc="urn:oasis:names:tc:ubl:CommonBasicComponents:1:0" xmlns:cct="urn:oasis:names:tc:ubl:CoreComponentTypes:1:0" xmlns:udt="urn:oasis:names:tc:ubl:UnspecializedDatatypes:1:0" xmlns="urn:sfti:documents:ObjectEnvelope:1:0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DocumentReference>
<DocumentID>2522987548</DocumentID>
<IssueDate>2017-01-04</IssueDate>
<IssuerID>CGI</IssuerID>
<DocumentType>urn:sfti:documents:BasicInvoice:1:0</DocumentType>
</DocumentReference>
<CreationDateTime>2017-01-04T05:48:14</CreationDateTime>
</ObjectEnvelope>
</sh:StandardBusinessDocument>

我希望它看起来像这样:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Invoice xmlns="urn:sfti:documents:BasicInvoice:1:0" xmlns:cac="urn:sfti:CommonAggregateComponents:1:0" xmlns:cbc="urn:oasis:names:tc:ubl:CommonBasicComponents:1:0" xmlns:ccts="urn:oasis:names:tc:ubl:CoreComponentParameters:1:0" xmlns:cur="urn:oasis:names:tc:ubl:codelist:CurrencyCode:1:0" xmlns:sdt="urn:oasis:names:tc:ubl:SpecializedDatatypes:1:0" xmlns:udt="urn:oasis:names:tc:ubl:UnspecializedDatatypes:1:0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ID>2522987548</ID>
  <cbc:IssueDate>2017-01-01</cbc:IssueDate>
  <InvoiceTypeCode>380</InvoiceTypeCode>
  <cbc:Note>Vid frågor gällande resedebiteringar, kontakta din lokala resebyrå. Övrigt, kontakta Kundservice.</cbc:Note>
  <InvoiceCurrencyCode>SEK</InvoiceCurrencyCode>
  <LineItemCountNumeric>4</LineItemCountNumeric>
  <AdditionalDocumentReference>
    <cac:ID identificationSchemeID="CT">197911</cac:ID>
  </AdditionalDocumentReference>
  <AdditionalDocumentReference>
    <cac:ID identificationSchemeID="ACD">197911</cac:ID>
  </AdditionalDocumentReference>
  <cac:BuyerParty>
    <cac:Party>
      <cac:PartyIdentification>
        <cac:ID identificationSchemeID="92">5560452103</cac:ID>
      </cac:PartyIdentification>
      <cac:PartyName>
        <TwoHundreedMoreFields>...</TwoHundreedMoreFields>
      </cac:PartyName>
    </cac:Party>
  </cac:BuyerParty>
  <cac:SellerParty>
    <cac:Party>
      <cac:PartyIdentification>
        <cac:ID identificationSchemeID="91">5164060120</cac:ID>
      </cac:PartyIdentification>
      <cac:PartyName>
        <TwoHundreedMoreFields>...</TwoHundreedMoreFields>
      </cac:PartyName>
    </cac:Party>
  </cac:SellerParty>
  <cac:InvoiceLine>
    <cac:ID>31</cac:ID>
    <cbc:InvoicedQuantity quantityUnitCode="">1.00</cbc:InvoicedQuantity>
    <cbc:LineExtensionAmount amountCurrencyID="SEK">340.00</cbc:LineExtensionAmount>
    <cbc:Note>ARLANDA PARKERING  STHLM ARLANDA  Netto: 340,00  Moms: 0,00  Brutto: 340,00</cbc:Note>
  </cac:InvoiceLine>
  <cac:InvoiceLine>
    <cac:ID>32</cac:ID>
    <cbc:InvoicedQuantity quantityUnitCode="">1.00</cbc:InvoicedQuantity>
    <cbc:LineExtensionAmount amountCurrencyID="SEK">2273.00</cbc:LineExtensionAmount>
    <cbc:Note>Something AB  Bromma  Netto: 2273,00  Moms: 0,00  Brutto: 2273,00</cbc:Note>
  </cac:InvoiceLine>
</Invoice>

我用 XSLT 尝试了几种不同的方法,以剪掉我需要但没有一个可以完全工作的部分。

例子:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sh="urn:sfti:documents:StandardBusinessDocumentHeader" xmlns:cac="urn:sfti:CommonAggregateComponents:1:0" version="1.0">

<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>
<xsl:template match="Invoice">
  <xsl:apply-templates/>
  </xsl:template>
<xsl:template match="sh:StandardBusinessDocumentHeader"/>
<xsl:template match="ObjectEnvelope"/>
</xsl:stylesheet>

或者:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sh="urn:sfti:documents:StandardBusinessDocumentHeader" version="1.0">
  <xsl:output method="xml" indent="yes"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="/">
   <Invoice xmlns="urn:sfti:documents:BasicInvoice:1:0" >
    <xsl:copy-of select="/sh:StandardBusinessDocument/*"/>
     </Invoice>
 </xsl:template>
<xsl:template match="sh:StandardBusinessDocumentHeader"/>
<xsl:template match="ObjectEnvelope"/>
</xsl:stylesheet>

请帮忙。

我正在使用http://www.utilities-online.info/xsltransformation/#.WHX9klPhD-j来验证代码。很棒的小页面。

问候, 斯万特

4

1 回答 1

1

尝试:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:inv="urn:sfti:documents:BasicInvoice:1:0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/">
    <xsl:copy-of select="/*/inv:Invoice"/>
</xsl:template>

</xsl:stylesheet>
于 2017-01-11T12:10:29.070 回答