【问题标题】:Create XSLT for copy of entire XML but update few tags with static value为整个 XML 的副本创建 XSLT,但使用静态值更新几个标签
【发布时间】:2016-07-06 20:05:31
【问题描述】:

我想创建 XSLT 来复制相同的输入 XML,但想用静态值更改一些 XML 标记。

我曾尝试自行构建 XSLT,但我可以看到输出 XML 与输入 XML 相同。

这是输入 XML 文件

<?xml version="1.0" encoding="utf-8"?>
<Document
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  SystemVersion="7.00.3.71.03"
  System="HubBroker"
  Version="101"
  xmlns="http://rep.evenex.dk/schema/evenex/eBusiness_01">
  <Header>
    <SenderEndpointID qualifier="CVR">00000000</SenderEndpointID>
    <ReceiverEndpointID qualifier="EAN">6564654656546</ReceiverEndpointID>
    <CreatedDate>2016-04-07</CreatedDate>
    <CreatedTime>12:25:59</CreatedTime>
    <EDIRefNo>24721</EDIRefNo>
    <Test>false</Test>
    <AcknowledgementRequest>Yes</AcknowledgementRequest>
    <MailBounce>false</MailBounce>
    <AgreementNo>0000</AgreementNo>
    <InternalMessage>false</InternalMessage>
  </Header>
  <Body>
    <OriginalReceiverEndpointID>0000</OriginalReceiverEndpointID>
    <ReferencedDocumentType>INVOIC</ReferencedDocumentType>
    <DispatchReference>28373</DispatchReference>
    <DocumentType>INVOIC</DocumentType>
    <DocumentNo>24721</DocumentNo>
    <ReceiptStatus>false</ReceiptStatus>
    <ResponseIndicator>12</ResponseIndicator>
    <ReferencedInvoiceNo />
    <ReferencedCreditNoteNo />
    <DocumentDate>2016-04-07</DocumentDate>
    <StartDateCatalogue>2016-04-07</StartDateCatalogue>
    <EndDateCatalogue>2016-04-07</EndDateCatalogue>
    <ShipmentDate>2016-04-07</ShipmentDate>
    <DueDate>2016-05-30</DueDate>
    <InvoiceDate>2016-04-07</InvoiceDate>
    <PmtDiscountDate>2016-04-07</PmtDiscountDate>
    <RequestedDeliveryDate>2016-04-07</RequestedDeliveryDate>
    <PromisedDeliveryDate>2016-04-07</PromisedDeliveryDate>
    <PromisedDeliveryTime>00:00:00</PromisedDeliveryTime>
    <OrderDate>2016-04-07</OrderDate>
    <QuoteNo>0000</QuoteNo>
    <CampaignNo>0000</CampaignNo>
    <AccountCode>KONTOOVERFØRSEL</AccountCode>
    <OrderNo>PO5101903</OrderNo>
    <BankName>Danske Bank</BankName>
    <BankBranchNo>4394</BankBranchNo>
    <BankAccountNo>4795026355</BankAccountNo>
    <IBAN />
    <SWIFT />
    <PaymentType />
    <PaymentID>4795026355</PaymentID>
    <PaymentVendorNo />
    <PaymentTermsCode>KONTOOVERFØRSEL</PaymentTermsCode>
    <CurrencyCode>DKK</CurrencyCode>
    <ShipmentNo>28373</ShipmentNo>
    <ContractNo>0000</ContractNo>
    <PriceListNo>0000</PriceListNo>
    <ExternalDocumentNo>PO5101903</ExternalDocumentNo>
    <PayableAmount>9756.25</PayableAmount>
    <TaxableAmount>7805.00</TaxableAmount>
    <TaxAmount>1951.25</TaxAmount>
    <TaxInclusiveAmount>9756.25</TaxInclusiveAmount>
    <TotalItemAmount>7805.00</TotalItemAmount>
    <TotalDiscountAmount>0</TotalDiscountAmount>
    <TotalChargeAmount>0</TotalChargeAmount>
    <PaymentDiscountPercent>0.0</PaymentDiscountPercent>
    <NetTotal>0.0</NetTotal>
    <ShipmentMethodCode>ABLAGER</ShipmentMethodCode>
    <SeasonText>0000</SeasonText>
    <Collection>0000</Collection>
    <CatalogueFunctionCode>9</CatalogueFunctionCode>
    <Comments>
      <Comment>Disp.: h914hje</Comment>
    </Comments>
    <FreeText>
      <Text no="DEL">
        <TextString>Disp.: h914hje</TextString>
      </Text>
    </FreeText>
    <References>
      <Ref type="ON">
        <Reference>PO5101903</Reference>
      </Ref>
    </References>
    <YourReference />
    <Rounding>0.0</Rounding>
    <CollectionDate>2016-04-07</CollectionDate>
    <CollectionTime>00:00:00</CollectionTime>
    <LoadIndicator>2</LoadIndicator>
    <TransportPriority>3</TransportPriority>
    <TransportRefNo />
    <TransportPmtIndicator />
    <TransportMethodCode>1</TransportMethodCode>
    <Charges>
      <Charge type="FREIGHT">
        <Amount>0.00</Amount>
        <TaxCategory>S</TaxCategory>
        <TaxAmount>0.0</TaxAmount>
        <Percent>0.0</Percent>
      </Charge>
    </Charges>
    <Allowances>
      <Allowance type="Standard">
        <Amount>0.00</Amount>
        <TaxCategory>S</TaxCategory>
        <TaxAmount>0.0</TaxAmount>
        <Percent>0.0</Percent>
      </Allowance>
    </Allowances>
    <ExciseDuties>
      <ExciseDuty type="9">
        <Amount>0.0</Amount>
        <TaxCategory>S</TaxCategory>
        <TaxAmount>0.0</TaxAmount>
        <Percent>0.0</Percent>
      </ExciseDuty>
    </ExciseDuties>
    <InvoiceDiscounts>
      <InvoiceDiscount DiscountType="3">
        <DiscountPeriodUnit>Day</DiscountPeriodUnit>
        <DiscountPeriod />
        <DiscountPercent />
      </InvoiceDiscount>
    </InvoiceDiscounts>
    <Parties>
      <Party type="Billto">
        <No>6564654656546</No>
      </Party>
      <Party type="Sellto">
        <No>6564654656546</No>
        <Name>Denmark Danmark A/S</Name>
        <Name2 />
        <Postbox />
        <Address>Anelystparken 16</Address>
        <Address2 />
        <BuildingNumber />
        <City>Mundelstrup</City>
        <PostCode>8381</PostCode>
        <CountryRegionCode>DK</CountryRegionCode>
        <County />
        <ContactRole />
        <VATRegNo />
        <Contact>Ikke angivet</Contact>
        <ContactPhoneNo />
        <ContactFaxNo />
        <ContactEmail />
        <SupplierNoByCustomer />
      </Party>
      <Party type="Supplier">
        <No>00000000</No>
        <Name>asd asd A/S</Name>
        <Name2 />
        <Postbox />
        <Address>Gejlhavegård 17</Address>
        <Address2 />
        <BuildingNumber />
        <City>Kolding</City>
        <PostCode>6000</PostCode>
        <CountryRegionCode>DK</CountryRegionCode>
        <County />
        <ContactRole />
        <VATRegNo>
          DK00000000
        </VATRegNo>
        <Contact />
        <ContactPhoneNo />
        <ContactFaxNo />
        <ContactEmail />
        <SupplierNoByCustomer />
      </Party>
      <Party type="Shipto">
        <No>19555305</No>
        <Name />
        <Name2 />
        <Postbox />
        <Address>
          Denmark Hjørring
          Frederikshavnsvej 290
        </Address>
        <Address2 />
        <BuildingNumber />
        <City>Hjørring</City>
        <PostCode>9800</PostCode>
        <CountryRegionCode>DK</CountryRegionCode>
        <County />
        <ContactRole />
        <VATRegNo />
        <Contact />
        <ContactPhoneNo />
        <ContactFaxNo />
        <ContactEmail />
        <SupplierNoByCustomer />
      </Party>
    </Parties>
    <TaxSubtotals>
      <TaxSubtotal type="S">
        <TaxableAmount>7805.00</TaxableAmount>
        <TaxAmount>1951.25</TaxAmount>
        <TaxCategory>
          <ID>S</ID>
          <Percent>25.00</Percent>
          <TaxScheme>
            <ID>VAT</ID>
          </TaxScheme>
        </TaxCategory>
      </TaxSubtotal>
    </TaxSubtotals>
    <Lines>
      <Line>
        <LineNo>1</LineNo>
        <LineRefNo>1</LineRefNo>
        <EANNo>0200100218620</EANNo>
        <ItemNo>OL 0308 B</ItemNo>
        <RequestNotification>3</RequestNotification>
        <SublineReference>1</SublineReference>
        <RequestedDeliveryDate>2016-04-07</RequestedDeliveryDate>
        <PromisedDeliveryDate>2016-04-07</PromisedDeliveryDate>
        <PlannedDeliveryDate>2016-04-07</PlannedDeliveryDate>
        <PlannedShipmentDate>2016-04-07</PlannedShipmentDate>
        <ShipmentDate>2016-04-07</ShipmentDate>
        <EarliestDeliveryDate>2016-04-07</EarliestDeliveryDate>
        <LatestDeliveryDate>2016-04-07</LatestDeliveryDate>
        <ExpiryDate>2016-04-07</ExpiryDate>
        <Description>Stålvask 400 x 340 mm</Description>
        <GrossWeight>0</GrossWeight>
        <NetWeight>0</NetWeight>
        <PacketType>Box</PacketType>
        <UnitsperParcel>0</UnitsperParcel>
        <UnitVolume>0</UnitVolume>
        <UnitCost>0</UnitCost>
        <Quantity>5.00</Quantity>
        <OutstandingQuantity>0</OutstandingQuantity>
        <QuantityShipped>0</QuantityShipped>
        <MinimumQuantity>0</MinimumQuantity>
        <CreditedQuantity>0</CreditedQuantity>
        <QuantityInvoiced>5.00</QuantityInvoiced>
        <UnitofMeasure>PCE</UnitofMeasure>
        <UnitPrice>198.00</UnitPrice>
        <NetUnitPrice>198.00</NetUnitPrice>
        <Amount>990.00</Amount>
        <AmountIncludingVAT>1237.50</AmountIncludingVAT>
        <LineExtensionAmount>990.00</LineExtensionAmount>
        <InvDiscAmounttoInvoice>0</InvDiscAmounttoInvoice>
        <RetailPrice>0</RetailPrice>
        <TaxSubtotals>
          <TaxSubtotal type="S">
            <TaxableAmount>990.00</TaxableAmount>
            <TaxAmount>247.50</TaxAmount>
            <TaxCategory>
              <ID>S</ID>
              <Percent>25.00</Percent>
              <TaxScheme>
                <ID>VAT</ID>
              </TaxScheme>
            </TaxCategory>
          </TaxSubtotal>
        </TaxSubtotals>
        <LineDiscountPct>0</LineDiscountPct>
        <LineDiscountAmount>0.00</LineDiscountAmount>
      </Line>
    </Lines>
  </Body>
</Document>

我想生成相同的输出文件,但使用静态值更新的标签很少。

这是我尝试制作的 xslt 代码,

<?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="http://rep.evenex.dk/schema/evenex/eBusiness_01">  
  <xsl:strip-space elements="*"/>
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="Header">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
      <xsl:element name="SenderEndpointID">11111111</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>

我想用固定值 '11111111' 更新 Header 标记中的 SenderEndpointID

还有&lt;No&gt;&lt;VATRegNo&gt; 标记在&lt;Party type="Supplier"&gt; 内 - 其余标记将保持不变。

<Party type="Supplier">
   <No>11111111</No>        
   <VATRegNo>DK11111111</VATRegNo>       
</Party>

所以最终输出应该是这样的

<?xml version="1.0" encoding="utf-8"?>
<Document
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  SystemVersion="7.00.3.71.03"
  System="HubBroker"
  Version="101"
  xmlns="http://rep.evenex.dk/schema/evenex/eBusiness_01">
  <Header>
    <SenderEndpointID qualifier="CVR">11111111</SenderEndpointID>
    <ReceiverEndpointID qualifier="EAN">6564654656546</ReceiverEndpointID>
    <CreatedDate>2016-04-07</CreatedDate>
    <CreatedTime>12:25:59</CreatedTime>
    <EDIRefNo>24721</EDIRefNo>
    <Test>false</Test>
    <AcknowledgementRequest>Yes</AcknowledgementRequest>
    <MailBounce>false</MailBounce>
    <AgreementNo>0000</AgreementNo>
    <InternalMessage>false</InternalMessage>
  </Header>
  <Body>
    <OriginalReceiverEndpointID>0000</OriginalReceiverEndpointID>
    <ReferencedDocumentType>INVOIC</ReferencedDocumentType>
    <DispatchReference>28373</DispatchReference>
    <DocumentType>INVOIC</DocumentType>
    <DocumentNo>24721</DocumentNo>
    <ReceiptStatus>false</ReceiptStatus>
    <ResponseIndicator>12</ResponseIndicator>
    <ReferencedInvoiceNo />
    <ReferencedCreditNoteNo />
    <DocumentDate>2016-04-07</DocumentDate>
    <StartDateCatalogue>2016-04-07</StartDateCatalogue>
    <EndDateCatalogue>2016-04-07</EndDateCatalogue>
    <ShipmentDate>2016-04-07</ShipmentDate>
    <DueDate>2016-05-30</DueDate>
    <InvoiceDate>2016-04-07</InvoiceDate>
    <PmtDiscountDate>2016-04-07</PmtDiscountDate>
    <RequestedDeliveryDate>2016-04-07</RequestedDeliveryDate>
    <PromisedDeliveryDate>2016-04-07</PromisedDeliveryDate>
    <PromisedDeliveryTime>00:00:00</PromisedDeliveryTime>
    <OrderDate>2016-04-07</OrderDate>
    <QuoteNo>0000</QuoteNo>
    <CampaignNo>0000</CampaignNo>
    <AccountCode>KONTOOVERFØRSEL</AccountCode>
    <OrderNo>PO5101903</OrderNo>
    <BankName>Danske Bank</BankName>
    <BankBranchNo>4394</BankBranchNo>
    <BankAccountNo>4795026355</BankAccountNo>
    <IBAN />
    <SWIFT />
    <PaymentType />
    <PaymentID>4795026355</PaymentID>
    <PaymentVendorNo />
    <PaymentTermsCode>KONTOOVERFØRSEL</PaymentTermsCode>
    <CurrencyCode>DKK</CurrencyCode>
    <ShipmentNo>28373</ShipmentNo>
    <ContractNo>0000</ContractNo>
    <PriceListNo>0000</PriceListNo>
    <ExternalDocumentNo>PO5101903</ExternalDocumentNo>
    <PayableAmount>9756.25</PayableAmount>
    <TaxableAmount>7805.00</TaxableAmount>
    <TaxAmount>1951.25</TaxAmount>
    <TaxInclusiveAmount>9756.25</TaxInclusiveAmount>
    <TotalItemAmount>7805.00</TotalItemAmount>
    <TotalDiscountAmount>0</TotalDiscountAmount>
    <TotalChargeAmount>0</TotalChargeAmount>
    <PaymentDiscountPercent>0.0</PaymentDiscountPercent>
    <NetTotal>0.0</NetTotal>
    <ShipmentMethodCode>ABLAGER</ShipmentMethodCode>
    <SeasonText>0000</SeasonText>
    <Collection>0000</Collection>
    <CatalogueFunctionCode>9</CatalogueFunctionCode>
    <Comments>
      <Comment>Disp.: h914hje</Comment>
    </Comments>
    <FreeText>
      <Text no="DEL">
        <TextString>Disp.: h914hje</TextString>
      </Text>
    </FreeText>
    <References>
      <Ref type="ON">
        <Reference>PO5101903</Reference>
      </Ref>
    </References>
    <YourReference />
    <Rounding>0.0</Rounding>
    <CollectionDate>2016-04-07</CollectionDate>
    <CollectionTime>00:00:00</CollectionTime>
    <LoadIndicator>2</LoadIndicator>
    <TransportPriority>3</TransportPriority>
    <TransportRefNo />
    <TransportPmtIndicator />
    <TransportMethodCode>1</TransportMethodCode>
    <Charges>
      <Charge type="FREIGHT">
        <Amount>0.00</Amount>
        <TaxCategory>S</TaxCategory>
        <TaxAmount>0.0</TaxAmount>
        <Percent>0.0</Percent>
      </Charge>
    </Charges>
    <Allowances>
      <Allowance type="Standard">
        <Amount>0.00</Amount>
        <TaxCategory>S</TaxCategory>
        <TaxAmount>0.0</TaxAmount>
        <Percent>0.0</Percent>
      </Allowance>
    </Allowances>
    <ExciseDuties>
      <ExciseDuty type="9">
        <Amount>0.0</Amount>
        <TaxCategory>S</TaxCategory>
        <TaxAmount>0.0</TaxAmount>
        <Percent>0.0</Percent>
      </ExciseDuty>
    </ExciseDuties>
    <InvoiceDiscounts>
      <InvoiceDiscount DiscountType="3">
        <DiscountPeriodUnit>Day</DiscountPeriodUnit>
        <DiscountPeriod />
        <DiscountPercent />
      </InvoiceDiscount>
    </InvoiceDiscounts>
    <Parties>
      <Party type="Billto">
        <No>6564654656546</No>
      </Party>
      <Party type="Sellto">
        <No>6564654656546</No>
        <Name>Denmark Danmark A/S</Name>
        <Name2 />
        <Postbox />
        <Address>Anelystparken 16</Address>
        <Address2 />
        <BuildingNumber />
        <City>Mundelstrup</City>
        <PostCode>8381</PostCode>
        <CountryRegionCode>DK</CountryRegionCode>
        <County />
        <ContactRole />
        <VATRegNo />
        <Contact>Ikke angivet</Contact>
        <ContactPhoneNo />
        <ContactFaxNo />
        <ContactEmail />
        <SupplierNoByCustomer />
      </Party>
      <Party type="Supplier">
        <No>11111111</No>
        <Name>asd asd A/S</Name>
        <Name2 />
        <Postbox />
        <Address>Gejlhavegård 17</Address>
        <Address2 />
        <BuildingNumber />
        <City>Kolding</City>
        <PostCode>6000</PostCode>
        <CountryRegionCode>DK</CountryRegionCode>
        <County />
        <ContactRole />
        <VATRegNo>
          DK11111111
        </VATRegNo>
        <Contact />
        <ContactPhoneNo />
        <ContactFaxNo />
        <ContactEmail />
        <SupplierNoByCustomer />
      </Party>
      <Party type="Shipto">
        <No>19555305</No>
        <Name />
        <Name2 />
        <Postbox />
        <Address>
          Denmark Hjørring
          Frederikshavnsvej 290
        </Address>
        <Address2 />
        <BuildingNumber />
        <City>Hjørring</City>
        <PostCode>9800</PostCode>
        <CountryRegionCode>DK</CountryRegionCode>
        <County />
        <ContactRole />
        <VATRegNo />
        <Contact />
        <ContactPhoneNo />
        <ContactFaxNo />
        <ContactEmail />
        <SupplierNoByCustomer />
      </Party>
    </Parties>
    <TaxSubtotals>
      <TaxSubtotal type="S">
        <TaxableAmount>7805.00</TaxableAmount>
        <TaxAmount>1951.25</TaxAmount>
        <TaxCategory>
          <ID>S</ID>
          <Percent>25.00</Percent>
          <TaxScheme>
            <ID>VAT</ID>
          </TaxScheme>
        </TaxCategory>
      </TaxSubtotal>
    </TaxSubtotals>
    <Lines>
      <Line>
        <LineNo>1</LineNo>
        <LineRefNo>1</LineRefNo>
        <EANNo>0200100218620</EANNo>
        <ItemNo>OL 0308 B</ItemNo>
        <RequestNotification>3</RequestNotification>
        <SublineReference>1</SublineReference>
        <RequestedDeliveryDate>2016-04-07</RequestedDeliveryDate>
        <PromisedDeliveryDate>2016-04-07</PromisedDeliveryDate>
        <PlannedDeliveryDate>2016-04-07</PlannedDeliveryDate>
        <PlannedShipmentDate>2016-04-07</PlannedShipmentDate>
        <ShipmentDate>2016-04-07</ShipmentDate>
        <EarliestDeliveryDate>2016-04-07</EarliestDeliveryDate>
        <LatestDeliveryDate>2016-04-07</LatestDeliveryDate>
        <ExpiryDate>2016-04-07</ExpiryDate>
        <Description>Stålvask 400 x 340 mm</Description>
        <GrossWeight>0</GrossWeight>
        <NetWeight>0</NetWeight>
        <PacketType>Box</PacketType>
        <UnitsperParcel>0</UnitsperParcel>
        <UnitVolume>0</UnitVolume>
        <UnitCost>0</UnitCost>
        <Quantity>5.00</Quantity>
        <OutstandingQuantity>0</OutstandingQuantity>
        <QuantityShipped>0</QuantityShipped>
        <MinimumQuantity>0</MinimumQuantity>
        <CreditedQuantity>0</CreditedQuantity>
        <QuantityInvoiced>5.00</QuantityInvoiced>
        <UnitofMeasure>PCE</UnitofMeasure>
        <UnitPrice>198.00</UnitPrice>
        <NetUnitPrice>198.00</NetUnitPrice>
        <Amount>990.00</Amount>
        <AmountIncludingVAT>1237.50</AmountIncludingVAT>
        <LineExtensionAmount>990.00</LineExtensionAmount>
        <InvDiscAmounttoInvoice>0</InvDiscAmounttoInvoice>
        <RetailPrice>0</RetailPrice>
        <TaxSubtotals>
          <TaxSubtotal type="S">
            <TaxableAmount>990.00</TaxableAmount>
            <TaxAmount>247.50</TaxAmount>
            <TaxCategory>
              <ID>S</ID>
              <Percent>25.00</Percent>
              <TaxScheme>
                <ID>VAT</ID>
              </TaxScheme>
            </TaxCategory>
          </TaxSubtotal>
        </TaxSubtotals>
        <LineDiscountPct>0</LineDiscountPct>
        <LineDiscountAmount>0.00</LineDiscountAmount>
      </Line>
    </Lines>
  </Body>
</Document>

任何帮助将不胜感激

谢谢

【问题讨论】:

    标签: xml xslt


    【解决方案1】:

    如果您想更新 XML 中的 SenderEnpointID,您确实需要一个与该元素匹配的模板。但是,您还需要考虑命名空间。

    这是因为在输入 XML 中,SenderEnpointID 元素位于默认命名空间 http://rep.evenex.dk/schema/evenex/eBusiness_01 中。尽管您还在 XSLT 中定义了默认命名空间,但这不适用于匹配属性中的 xpath 表达式。

    要处理这个问题,您必须再次使用前缀声明命名空间,并在您的 xpath 表达式中使用它。

    xmlns:e="http://rep.evenex.dk/schema/evenex/eBusiness_01"
    

    所以,模板将如下所示

      <xsl:template match="e:SenderEndpointID">
         <xsl:copy>
            <xsl:apply-templates select="@*|*"/>
            <xsl:text>11111111</xsl:text>
         </xsl:copy>
      </xsl:template> 
    

    或者,如果您只是想更新 SenderEndpointID 的文本,您可以用这个更简单的模板替换当前匹配它的模板:

     <xsl:template match="e:SenderEndpointID/text()">
        <xsl:text>11111111</xsl:text>
     </xsl:template> 
    

    Party 下的元素可以有类似的模板。例如

      <xsl:template match="e:Party[@type='Supplier']/e:No">
          <No>
            <xsl:text>11111111</xsl:text>
          </No>
      </xsl:template>
    

    或者也许只是这个

      <xsl:template match="e:Party[@type='Supplier']/e:No/text()">
          <xsl:text>11111111</xsl:text>
      </xsl:template>
    

    试试这个...

    <xsl:stylesheet version="1.0"
      xmlns:xsl    = "http://www.w3.org/1999/XSL/Transform"
      xmlns:xsi    = "http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://rep.evenex.dk/schema/evenex/eBusiness_01"  
      xmlns:e="http://rep.evenex.dk/schema/evenex/eBusiness_01">  
    
      <xsl:strip-space elements="*"/>
    
      <xsl:output method="xml" indent="yes"/>
    
      <xsl:template match="e:SenderEndpointID/text()">
          <xsl:text>11111111</xsl:text>
      </xsl:template> 
    
      <xsl:template match="e:Party[@type='Supplier']/e:No/text()">
          <xsl:text>11111111</xsl:text>
      </xsl:template>
    
      <xsl:template match="e:Party[@type='Supplier']/e:VATRegNo/text()">
          <xsl:text>DK11111111</xsl:text>
      </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>
    

    请注意,如果您能够使用 XSLT 2.0,则可以使用 xpath-default-namespace,它将为 xpath 表达式设置默认命名空间。

    【讨论】:

    • 它在 Header 中添加了额外的标签,而不是更新现有的标签。
    • 感谢蒂姆,如果我们有 3 个具有不同属性的派对标签,我们如何更新特定的派对标签。你可以看到输入文件
    • 还有一个问题。如何从任何标签中删除字母。例如。我想从 PO5103553 中删除“PO”
    • 这可能超出了这个原始问题的范围,所以最好在 StackOverflow 上提出一个全新的问题(问题是为了让整个社区受益,所以在 cmets 上隐藏东西并不是真的推荐)。不过作为提示,请查看 translate 函数,因为这可能适合您的需求。
    • 好的,没关系。我可以试试我自己..如果我卡住了问个问题
    猜你喜欢
    • 1970-01-01
    • 2019-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多