Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何在XSLT中将所有标记从一个节点复制到另一个节点,同时将其他内容复制为

如何在XSLT中将所有标记从一个节点复制到另一个节点,同时将其他内容复制为
EN

Stack Overflow用户
提问于 2016-03-29 22:24:08
回答 2查看 1.3K关注 0票数 2

我想要创建XSLT来复制相同的输入XML,但是要将一些元素从一个标记复制到同级标记。

这是我的输入文件http://pastebin.com/7hVmRcqN

我希望输出与输入文件相同,但以下标签中的内容除外。<cac:Delivery>....</cac:Delivery><cac:Delivery><cac:Address> .... </cac:Address>复制所有元素并放入新创建的标签中

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<cac:DeliveryParty><cac:PostalAddress> ... </cac:PostalAddress></cac:DeliveryParty>

在这里,<cac:DeliveryParty>已经存在于输入XML中。需要在<cac:PostalAddress> ... </cac:PostalAddress>中创建新的标记<cac:DeliveryParty>... </cac:DeliveryParty>,而来自<cac:Delivery><cac:Address> .... </cac:Address>的所有标记都将在<cac:PostalAddress> ... </cac:PostalAddress>中复制。

标记及其原始输入文件中的所有内容。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<cac:Delivery>
<cac:DeliveryLocation>
  <cbc:Description>er</cbc:Description>
  <cac:Address>
    <cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
    <cbc:StreetName>sadasd</cbc:StreetName>
    <cbc:CityName>asd</cbc:CityName>
    <cbc:PostalZone>6630</cbc:PostalZone>
    <cac:Country>
      <cbc:IdentificationCode>DK</cbc:IdentificationCode>
    </cac:Country>
  </cac:Address>
</cac:DeliveryLocation>
<cac:DeliveryParty>
  <cbc:EndpointID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:EndpointID>
  <cac:PartyIdentification>
    <cbc:ID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:ID>
  </cac:PartyIdentification>
  <cac:PartyName>
    <cbc:Name>asd asd asd</cbc:Name>
  </cac:PartyName>
</cac:DeliveryParty>
</cac:Delivery>

因此,更新后的<cac:Delivery>..</cac:Delivery>标记如下所示。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<cac:Delivery>
    <cac:DeliveryLocation>
      <cbc:Description>er</cbc:Description>
      <cac:Address>
        <cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
        <cbc:StreetName>sadasd</cbc:StreetName>
        <cbc:CityName>asd</cbc:CityName>
        <cbc:PostalZone>6630</cbc:PostalZone>
        <cac:Country>
          <cbc:IdentificationCode>DK</cbc:IdentificationCode>
        </cac:Country>
      </cac:Address>
    </cac:DeliveryLocation>
    <cac:DeliveryParty>
      <cbc:EndpointID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:EndpointID>
      <cac:PartyIdentification>
        <cbc:ID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:ID>
      </cac:PartyIdentification>
      <cac:PartyName>
        <cbc:Name>asd asd asd</cbc:Name>
      </cac:PartyName>
      <cac:PostalAddress>
         <cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
         <cbc:StreetName>sadasd</cbc:StreetName>
         <cbc:CityName>asd</cbc:CityName>
         <cbc:PostalZone>6630</cbc:PostalZone>
         <cac:Country>
            <cbc:IdentificationCode>DK</cbc:IdentificationCode>
         </cac:Country>
       </cac:PostalAddress>
    </cac:DeliveryParty>
  </cac:Delivery>

下面是我试图制作的xslt代码,但不知道下一步该做什么

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
 xmlns:xsl    = "http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi    = "http://www.w3.org/2001/XMLSchema-instance"
    xmlns:oioubl = "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
    xmlns:cac    = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
    xmlns:cbc    = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
    xmlns:ccts   = "urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-2"
    xmlns:sdt    = "urn:oasis:names:specification:ubl:schema:xsd:SpecializedDatatypes-2"
    xmlns:udt    = "urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2">
  <!--Identity template,  provides default behavior that copies all content into the output -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="cac:DeliveryParty">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
      <xsl:element name="cac:PostalAddress">

      </xsl:element>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

XML的最终输出应该如下所示

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   <?xml version="1.0" encoding="UTF-8"?>
<!--XML file created by Microsoft Dynamics C5-->
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ccts="urn:un:unece:uncefact:documentation:2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <cbc:UBLVersionID schemeAgencyID="320" schemeAgencyName="urn:oioubl:id:profileid-1.1">2.0</cbc:UBLVersionID>
  <cbc:CustomizationID>OIOUBL-2.02</cbc:CustomizationID>
  <cbc:ProfileID schemeID="urn:oioubl:id:profileid-1.2" schemeAgencyID="320">Procurement-BilSim-1.0</cbc:ProfileID>
  <cbc:ID>Test123</cbc:ID>
  <cbc:IssueDate>2016-03-22</cbc:IssueDate>
  <cbc:InvoiceTypeCode listID="urn:oioubl:codelist:invoicetypecode-1.1" listAgencyID="320">380</cbc:InvoiceTypeCode>
  <cbc:DocumentCurrencyCode>DKK</cbc:DocumentCurrencyCode>
  <cbc:AccountingCost />
  <cac:OrderReference>
    <cbc:ID>Test321</cbc:ID>
    <cbc:SalesOrderID>Test212</cbc:SalesOrderID>
    <cbc:IssueDate>2016-03-21</cbc:IssueDate>
  </cac:OrderReference>
  <cac:AccountingSupplierParty>
    <cac:Party>
      <cbc:EndpointID schemeID="GLN" schemeAgencyID="9">9999999999999</cbc:EndpointID>
      <cac:PartyIdentification>
        <cbc:ID schemeID="DK:CVR">DK99999999</cbc:ID>
      </cac:PartyIdentification>
      <cac:PartyName>
        <cbc:Name>F &amp; H Com. A/S</cbc:Name>
      </cac:PartyName>
      <cac:PostalAddress>
        <cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
        <cbc:StreetName>Tets</cbc:StreetName>
        <cbc:InhouseMail>mail@test.dk</cbc:InhouseMail>
        <cbc:CityName>test</cbc:CityName>
        <cbc:PostalZone>8751</cbc:PostalZone>
        <cac:Country>
          <cbc:IdentificationCode>DK</cbc:IdentificationCode>
        </cac:Country>
      </cac:PostalAddress>
      <cac:PartyTaxScheme>
        <cbc:CompanyID schemeID="DK:SE">DK99999999</cbc:CompanyID>
        <cac:TaxScheme>
          <cbc:ID schemeID="urn:oioubl:id:taxschemeid-1.1" schemeAgencyID="320">63</cbc:ID>
          <cbc:Name>Moms</cbc:Name>
        </cac:TaxScheme>
      </cac:PartyTaxScheme>
      <cac:PartyLegalEntity>
        <cbc:RegistrationName>test</cbc:RegistrationName>
        <cbc:CompanyID schemeID="DK:CVR">DK99999999</cbc:CompanyID>
      </cac:PartyLegalEntity>
      <cac:Contact>
        <cbc:ID>ZZ</cbc:ID>
        <cbc:Name>DK99999999</cbc:Name>
        <cbc:Telephone>DK99999999</cbc:Telephone>
        <cbc:Telefax>DK99999999</cbc:Telefax>
        <cbc:ElectronicMail>DK99999999</cbc:ElectronicMail>
      </cac:Contact>
    </cac:Party>
  </cac:AccountingSupplierParty>
  <cac:AccountingCustomerParty>
    <cac:Party>
      <cbc:EndpointID schemeID="GLN" schemeAgencyID="9">8888888888888</cbc:EndpointID>
      <cac:PartyIdentification>
        <cbc:ID schemeID="DK:CVR">DK33333333</cbc:ID>
      </cac:PartyIdentification>
      <cac:PartyName>
        <cbc:Name>zdfsdf</cbc:Name>
      </cac:PartyName>
      <cac:PostalAddress>
        <cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
        <cbc:StreetName>etwf</cbc:StreetName>
        <cbc:CityName>asd</cbc:CityName>
        <cbc:PostalZone>6500</cbc:PostalZone>
        <cac:Country>
          <cbc:IdentificationCode>DK</cbc:IdentificationCode>
        </cac:Country>
      </cac:PostalAddress>
      <cac:PartyTaxScheme>
        <cbc:CompanyID schemeID="DK:SE">DK33333333</cbc:CompanyID>
        <cac:TaxScheme>
          <cbc:ID schemeID="urn:oioubl:id:taxschemeid-1.1" schemeAgencyID="320">63</cbc:ID>
          <cbc:Name>Moms</cbc:Name>
        </cac:TaxScheme>
      </cac:PartyTaxScheme>
      <cac:PartyLegalEntity>
        <cbc:RegistrationName>tesad</cbc:RegistrationName>
        <cbc:CompanyID schemeID="DK:CVR">DK33333333</cbc:CompanyID>
      </cac:PartyLegalEntity>
      <cac:Contact>
        <cbc:ID>ZZ</cbc:ID>
      </cac:Contact>
    </cac:Party>
  </cac:AccountingCustomerParty>
  <cac:BuyerCustomerParty>
    <cac:Party>
      <cbc:EndpointID schemeID="GLN" schemeAgencyID="9">5704707012544</cbc:EndpointID>
      <cac:PartyIdentification>
        <cbc:ID schemeID="DK:CVR">DK07012544</cbc:ID>
      </cac:PartyIdentification>
      <cac:PartyName>
        <cbc:Name>Davidsenshop.dk</cbc:Name>
      </cac:PartyName>
      <cac:PostalAddress>
        <cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
        <cbc:StreetName>Industrivej 36</cbc:StreetName>
        <cbc:InhouseMail>mail@davidsenshop.dk</cbc:InhouseMail>
        <cbc:CityName>Vamdrup</cbc:CityName>
        <cbc:PostalZone>6580</cbc:PostalZone>
        <cac:Country>
          <cbc:IdentificationCode>DK</cbc:IdentificationCode>
        </cac:Country>
      </cac:PostalAddress>
      <cac:PartyLegalEntity>
        <cbc:RegistrationName>Davidsenshop.dk</cbc:RegistrationName>
        <cbc:CompanyID schemeID="DK:CVR">DK07012544</cbc:CompanyID>
      </cac:PartyLegalEntity>
      <cac:Contact>
        <cbc:ID>test123</cbc:ID>
        <cbc:Telephone>78774800</cbc:Telephone>
        <cbc:ElectronicMail>mail@davidsenshop.dk</cbc:ElectronicMail>
      </cac:Contact>
    </cac:Party>
  </cac:BuyerCustomerParty>
  <cac:SellerSupplierParty>
    <cac:Party>
      <cbc:EndpointID schemeID="GLN" schemeAgencyID="9">5790002307478</cbc:EndpointID>
      <cac:PartyIdentification>
        <cbc:ID schemeID="DK:CVR">DK28893353</cbc:ID>
      </cac:PartyIdentification>
      <cac:PartyName>
        <cbc:Name>F &amp; H Com. A/S</cbc:Name>
      </cac:PartyName>
      <cac:PostalAddress>
        <cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
        <cbc:StreetName>Gl. Kattrupvej 4</cbc:StreetName>
        <cbc:InhouseMail>mail@fhcom.dk</cbc:InhouseMail>
        <cbc:CityName>Gedved</cbc:CityName>
        <cbc:PostalZone>8751</cbc:PostalZone>
        <cac:Country>
          <cbc:IdentificationCode>DK</cbc:IdentificationCode>
        </cac:Country>
      </cac:PostalAddress>
      <cac:PartyLegalEntity>
        <cbc:RegistrationName>F &amp; H Com. A/S</cbc:RegistrationName>
        <cbc:CompanyID schemeID="DK:CVR">DK28893353</cbc:CompanyID>
      </cac:PartyLegalEntity>
      <cac:Contact>
        <cbc:ID>ZZ</cbc:ID>
        <cbc:Name>Kenneth Rix Bløcher</cbc:Name>
        <cbc:Telephone>76273744</cbc:Telephone>
        <cbc:Telefax>76273748</cbc:Telefax>
        <cbc:ElectronicMail>mail@fhcom.dk</cbc:ElectronicMail>
      </cac:Contact>
    </cac:Party>
  </cac:SellerSupplierParty>
  <cac:Delivery>
    <cac:DeliveryLocation>
      <cbc:Description>er</cbc:Description>
      <cac:Address>
        <cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
        <cbc:StreetName>sadasd</cbc:StreetName>
        <cbc:CityName>asd</cbc:CityName>
        <cbc:PostalZone>6630</cbc:PostalZone>
        <cac:Country>
          <cbc:IdentificationCode>DK</cbc:IdentificationCode>
        </cac:Country>
      </cac:Address>
    </cac:DeliveryLocation>
    <cac:DeliveryParty>
      <cbc:EndpointID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:EndpointID>
      <cac:PartyIdentification>
        <cbc:ID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:ID>
      </cac:PartyIdentification>
      <cac:PartyName>
        <cbc:Name>asd asd asd</cbc:Name>
      </cac:PartyName>
      <cac:PostalAddress>
        <cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
        <cbc:StreetName>sadasd</cbc:StreetName>
        <cbc:CityName>asd</cbc:CityName>
        <cbc:PostalZone>6630</cbc:PostalZone>
        <cac:Country>
          <cbc:IdentificationCode>DK</cbc:IdentificationCode>
        </cac:Country>
      </cac:PostalAddress>
    </cac:DeliveryParty>
  </cac:Delivery>
  <cac:PaymentMeans>
    <cbc:ID>1</cbc:ID>
    <cbc:PaymentMeansCode>42</cbc:PaymentMeansCode>
    <cbc:PaymentDueDate>2016-04-15</cbc:PaymentDueDate>
    <cbc:PaymentChannelCode listID="urn:oioubl:codelist:paymentchannelcode-1.1" listAgencyID="320">DK:BANK</cbc:PaymentChannelCode>
    <cac:PayeeFinancialAccount>
      <cbc:ID>asd</cbc:ID>
      <cac:FinancialInstitutionBranch>
        <cbc:ID>test123</cbc:ID>
      </cac:FinancialInstitutionBranch>
    </cac:PayeeFinancialAccount>
  </cac:PaymentMeans>
  <cac:PaymentTerms>
    <cbc:Note>SPECIFIC</cbc:Note>
    <cbc:Amount currencyID="DKK">796.00</cbc:Amount>
  </cac:PaymentTerms>
  <cac:TaxTotal>
    <cbc:TaxAmount currencyID="DKK">159.20</cbc:TaxAmount>
    <cac:TaxSubtotal>
      <cbc:TaxableAmount currencyID="DKK">636.80</cbc:TaxableAmount>
      <cbc:TaxAmount currencyID="DKK">159.20</cbc:TaxAmount>
      <cac:TaxCategory>
        <cbc:ID schemeID="urn:oioubl:id:taxcategoryid-1.1" schemeAgencyID="320">StandardRated</cbc:ID>
        <cbc:Percent>25.00</cbc:Percent>
        <cac:TaxScheme>
          <cbc:ID schemeID="urn:oioubl:id:taxschemeid-1.1" schemeAgencyID="320">63</cbc:ID>
          <cbc:Name>Moms</cbc:Name>
        </cac:TaxScheme>
      </cac:TaxCategory>
    </cac:TaxSubtotal>
  </cac:TaxTotal>
  <cac:LegalMonetaryTotal>
    <cbc:LineExtensionAmount currencyID="DKK">636.80</cbc:LineExtensionAmount>
    <cbc:TaxExclusiveAmount currencyID="DKK">159.20</cbc:TaxExclusiveAmount>
    <cbc:TaxInclusiveAmount currencyID="DKK">796.00</cbc:TaxInclusiveAmount>
    <cbc:PayableAmount currencyID="DKK">796.00</cbc:PayableAmount>
  </cac:LegalMonetaryTotal>
  <cac:InvoiceLine>
    <cbc:ID>1</cbc:ID>
    <cbc:InvoicedQuantity unitCode="EA">1.00</cbc:InvoicedQuantity>
    <cbc:LineExtensionAmount currencyID="DKK">636.80</cbc:LineExtensionAmount>
    <cac:OrderLineReference>
      <cbc:LineID>1</cbc:LineID>
      <cac:OrderReference>
        <cbc:ID>test123</cbc:ID>
        <cbc:SalesOrderID>19070</cbc:SalesOrderID>
      </cac:OrderReference>
    </cac:OrderLineReference>
    <cac:Delivery>
      <cbc:ActualDeliveryDate>2016-03-22</cbc:ActualDeliveryDate>
    </cac:Delivery>
    <cac:TaxTotal>
      <cbc:TaxAmount currencyID="DKK">159.20</cbc:TaxAmount>
      <cac:TaxSubtotal>
        <cbc:TaxableAmount currencyID="DKK">636.80</cbc:TaxableAmount>
        <cbc:TaxAmount currencyID="DKK">159.20</cbc:TaxAmount>
        <cac:TaxCategory>
          <cbc:ID schemeID="urn:oioubl:id:taxcategoryid-1.1" schemeAgencyID="320">StandardRated</cbc:ID>
          <cbc:Percent>25.00</cbc:Percent>
          <cac:TaxScheme>
            <cbc:ID schemeID="urn:oioubl:id:taxschemeid-1.1" schemeAgencyID="320">63</cbc:ID>
            <cbc:Name>Moms</cbc:Name>
          </cac:TaxScheme>
        </cac:TaxCategory>
      </cac:TaxSubtotal>
    </cac:TaxTotal>
    <cac:Item>
      <cbc:Description>werwe</cbc:Description>
      <cbc:Name>werwer</cbc:Name>
      <cac:BuyersItemIdentification>
        <cbc:ID>10017</cbc:ID>
      </cac:BuyersItemIdentification>
      <cac:SellersItemIdentification>
        <cbc:ID>10017</cbc:ID>
      </cac:SellersItemIdentification>
    </cac:Item>
    <cac:Price>
      <cbc:PriceAmount currencyID="DKK">636.8000</cbc:PriceAmount>
      <cbc:BaseQuantity unitCode="EA">1.00</cbc:BaseQuantity>
      <cbc:OrderableUnitFactorRate>1</cbc:OrderableUnitFactorRate>
    </cac:Price>
  </cac:InvoiceLine>
</Invoice>

如能提供任何帮助,将不胜感激。

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-03-30 21:36:30

可以使用xsl:copy-of传递XPath参数,该参数引用当前cac:Delivery祖先中cac:Address的所有子级:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<xsl:element name="cac:PostalAddress">
    <xsl:copy-of select="../cac:DeliveryLocation/cac:Address/*"/>
</xsl:element>

下面是一个完整的工作示例

XML输入:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<cac:Delivery 
    xmlns:cac    = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
    xmlns:cbc    = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
>    
<cac:DeliveryLocation>
  <cbc:Description>er</cbc:Description>
  <cac:Address>
    <cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
    <cbc:StreetName>sadasd</cbc:StreetName>
    <cbc:CityName>asd</cbc:CityName>
    <cbc:PostalZone>6630</cbc:PostalZone>
    <cac:Country>
      <cbc:IdentificationCode>DK</cbc:IdentificationCode>
    </cac:Country>
  </cac:Address>
</cac:DeliveryLocation>
<cac:DeliveryParty>
  <cbc:EndpointID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:EndpointID>
  <cac:PartyIdentification>
    <cbc:ID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:ID>
  </cac:PartyIdentification>
  <cac:PartyName>
    <cbc:Name>asd asd asd</cbc:Name>
  </cac:PartyName>
</cac:DeliveryParty>
</cac:Delivery>

XSLT :

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl    = "http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi    = "http://www.w3.org/2001/XMLSchema-instance"
    xmlns:cac    = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
    xmlns:cbc    = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">

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

  <xsl:template match="cac:DeliveryParty">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
      <xsl:element name="cac:PostalAddress">
        <xsl:copy-of select="../cac:DeliveryLocation/cac:Address/*"/>
      </xsl:element>
    </xsl:copy>
  </xsl:template>

  <!--Identity template,  provides default behavior that copies all content into the output -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

输出:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0" encoding="UTF-8"?>
<cac:Delivery xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
              xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
   <cac:DeliveryLocation>
      <cbc:Description>er</cbc:Description>
      <cac:Address>
         <cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
         <cbc:StreetName>sadasd</cbc:StreetName>
         <cbc:CityName>asd</cbc:CityName>
         <cbc:PostalZone>6630</cbc:PostalZone>
         <cac:Country>
            <cbc:IdentificationCode>DK</cbc:IdentificationCode>
         </cac:Country>
      </cac:Address>
   </cac:DeliveryLocation>
   <cac:DeliveryParty>
      <cbc:EndpointID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:EndpointID>
      <cac:PartyIdentification>
         <cbc:ID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:ID>
      </cac:PartyIdentification>
      <cac:PartyName>
         <cbc:Name>asd asd asd</cbc:Name>
      </cac:PartyName>
      <cac:PostalAddress>
         <cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
         <cbc:StreetName>sadasd</cbc:StreetName>
         <cbc:CityName>asd</cbc:CityName>
         <cbc:PostalZone>6630</cbc:PostalZone>
         <cac:Country>
            <cbc:IdentificationCode>DK</cbc:IdentificationCode>
         </cac:Country>
      </cac:PostalAddress>
   </cac:DeliveryParty>
</cac:Delivery>
票数 3
EN

Stack Overflow用户

发布于 2016-03-31 21:03:16

在回答har07之前,我已经试过了。下面是我尝试过的XSLT

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl    = "http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi    = "http://www.w3.org/2001/XMLSchema-instance"
    xmlns:oioubl = "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
    xmlns:cac    = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
    xmlns:cbc    = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
    xmlns:ccts   = "urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-2"
    xmlns:sdt    = "urn:oasis:names:specification:ubl:schema:xsd:SpecializedDatatypes-2"
    xmlns:udt    = "urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2">
  <!--Identity template,  provides default behavior that copies all content into the output -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="cac:DeliveryParty">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
      <xsl:element name="cac:PostalAddress">
        <xsl:copy-of select="../cac:DeliveryLocation/cac:Address/cbc:AddressFormatCode" />
        <xsl:copy-of select="../cac:DeliveryLocation/cac:Address/cbc:StreetName" />
        <xsl:copy-of select="../cac:DeliveryLocation/cac:Address/cbc:CityName" />
        <xsl:copy-of select="../cac:DeliveryLocation/cac:Address/cbc:PostalZone" />
        <xsl:copy-of select="../cac:DeliveryLocation/cac:Address/cac:Country" />
      </xsl:element>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

但是我认为har07的方法要好得多,因为它将涵盖输入XML中的所有标记。在我的XSLT中,它只包含XSLT中列出的标记。

因此,我更喜欢遵循har07的XSLT脚本是最好的脚本。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl    = "http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi    = "http://www.w3.org/2001/XMLSchema-instance"
    xmlns:cac    = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
    xmlns:cbc    = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">

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

  <xsl:template match="cac:DeliveryParty">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
      <xsl:element name="cac:PostalAddress">
        <xsl:copy-of select="../cac:DeliveryLocation/cac:Address/*"/>
      </xsl:element>
    </xsl:copy>
  </xsl:template>

  <!--Identity template,  provides default behavior that copies all content into the output -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36301208

复制
相关文章
如何在SQL Server中将表从一个数据库复制到另一个数据库
在某些情况下,作为DBA,您需要将模式和特定表的内容从数据库复制到同一实例中或在不同的SQL实例中,例如从生产数据库中复制特定表到开发人员以进行测试或排除故障。 SQL Server提供了许多方法,可以用来执行表的数据和模式复制过程。为了研究这些方法中的每一个,我们将考虑下面的场景: 托管SQL服务器:localhost。这两个数据库都驻留在同一个SQL Server 2014实例中。 源数据库:AdventureWorks2012。 目标数据库:SQLShackDemo。 将从源数据库复制到目标数据库的表
程序你好
2018/07/20
8.3K0
flutter - 如何在Dart/Flutter中将某些元素从一个Map复制到新Map中?
由于keys返回 map 键的Iterable<String>,因此您可以使用where方法检查所需的键,然后可以基于旧 map 值填充值。
徐建国
2021/08/30
1.4K0
php获取所有节点的父节点和子节点
根据子节点获取所有的父节点以及父节点的父节点.. <?php $src = '[{"id":"1","name":"媒体(白名单)","pid":"0"},{"id":"2","name":"党媒公
黄啊码
2020/05/29
6.2K0
java 把文件从一个目录复制到另一个目录
方法一:简单粗暴,直接使用copy(),如果目标存在,先使用delete()删除,再复制;
崔笑颜
2020/06/08
1.9K0
Linux将一个文件夹或文件夹下的所有内容复制到另一个文件夹
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/124758.html原文链接:https://javaforall.cn
全栈程序员站长
2022/07/21
5.4K0
Linux将一个文件夹或文件夹下的所有内容复制到另一个文件夹
[译]将 Kubernetes 扩展至7500个节点
我们已经将 Kubernetes 集群扩展到了7500个节点,该集群主要是为 GPT-3、CLIP 和 DALL·E 等大型模型提供可扩展的基础设施,同时也为神经语言模型的缩放定律等快速的小规模迭代研究提供基础支持。将单个 Kubernetes 集群扩展到这种规模是很少见的,因而需要特别小心,但好处是一个简单的基础设施,使我们的机器学习研究团队能够更快地迁移和扩展,而不需要更改他们的代码。
我是阳明
2021/03/01
7270
SQL根据指定节点ID获取所有父级节点和子级节点
根据指定节点ID获取所有父节点 with temp as( select * from dbo.Category where Id=493 --表的主键ID union all select t.* from temp,dbo.Category t where temp.Pid=t.Id --父级ID=子级ID )select * from temp order by Level; [查询结果] 根据指定节点ID获取所有子节点 with temp as( select * from dbo.Category
段邵华
2019/08/01
6K0
java根据子节点获取它对应的所有父节点_java根据父节点查找子节点
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
全栈程序员站长
2022/10/01
6.9K0
树形结构已知子节点获取子节点所有父节点——任意目录/树
JS 树形结构 根据子节点找到所有上级,比如element-tree,已知路由上的子结点id,如何回填的 展开目录树?
周陆军博客
2023/05/07
3.3K0
将一个CentOS环境复制到另一个CentOS
「这是我参与2022首次更文挑战的第23天,活动详情查看:2022首次更文挑战」。
Java廖志伟
2022/03/07
5700
将一个CentOS环境复制到另一个CentOS
将一个CentOS环境复制到另一个CentOS
将一个CentOS环境复制到另一个CentOs,实现环境迁移或备份的功能 将CentOS2复制一份新的CentOS3出来,步骤如下: 创建新的CentOS3 这里的名称改吃CentOS3,后面的文件改名就是对应的这个名称 ISO映像文件路径修改,每个CentOS单独用一个ISO映像文件 直接启动 修改网络ip cd /etc/sysconfig/network-scripts/ vi ifc
Java廖志伟
2022/09/29
1.6K0
将一个CentOS环境复制到另一个CentOS
【Longhorn】能否部署到专用的节点,业务使用其他节点
Longhorn 作为分布式存储,当然是有点复杂的…作为集群的使用者,当然会有一种想法就是能否在集群中只用几个节点部署 Longhorn,万一出问题了,不影响用户在节点上的其他工作负载,就是单纯想隔离了。
runzhliu
2022/04/13
6960
【Longhorn】能否部署到专用的节点,业务使用其他节点
属性 元素的内容 创建,插入和删除节点 虚拟节点
表示HTML文档元素的HTMLElement对象定义了读/写属性。映射了元素的HTML属性。HTMLElement定义了通用的HTTP属性。以及事件处理程序的属性。特定的Element子类型为其元素定义了特定的属性。
mySoul
2018/08/07
2.4K0
如何在集群里服役新节点、退役旧节点(DataNode)
①准备机器,配置好JDK、hadoop的环境变量,在hdfs-site.xml和yarn-site.xml文件中分别配置NameNode和ResourceManager所在主机名 ②待服役成功后,启动datanode和nodemanager进程即可 ③服役了新的DN节点后,可以执行再平衡的命令,这个命令可以将集群中块进行重新平衡分配,实现负载均衡: ./start-balancer.sh
孙晨c
2020/07/14
8310
如何在100个节点集群上模拟10000个节点的集群?让DynoYARN来模拟吧
DynoYARN 是一种用于按需启动 YARN 集群并运行模拟 YARN 工作负载以进行规模测试的工具。由Linkedin开源。它可以在 100 个节点的 Hadoop 集群上模拟 10,000 个节点的 YARN 集群性能。
从大数据到人工智能
2022/04/08
8060
​[AAAI | 论文简读] GNN中非属性节点分类的优先标记
Preferential Labeling for Unattributed Node Classification in GNNs
智能生信
2022/12/29
4860
​[AAAI | 论文简读] GNN中非属性节点分类的优先标记
xpath库详解xpath入门获取所有节点 //子节点 /父节点 ..属性匹配 @文本获取按序选择节点轴选择
python爬虫抓取网页内容,需要对html或xml结构的数据进行解析,如果用正则,单是写正则表达式就让很多望而生畏了。
章鱼喵
2018/09/26
25.3K0
xpath库详解xpath入门获取所有节点 //子节点 /父节点 ..属性匹配 @文本获取按序选择节点轴选择
jquery 元素节点操作 - 创建节点、插入节点、删除节点
前面的篇章对于jquery的元素操作大部分是使用html()的方式来操作,这种直接使用字符串创建的方式也是性能最高的。
Devops海洋的渔夫
2019/05/31
9K0
点击加载更多

相似问题

XSLT在xml中将值从一个节点复制到另一个节点

10

XSLT:将属性从一个节点复制到另一个节点

22

XSLT -复制所有其他节点,添加1个新节点

42

将所有xml属性从一个节点复制到另一个节点

39

Drupal -自动将字段内容从一个节点复制到另一个节点

12
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文