【发布时间】: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
还有<No> 和<VATRegNo> 标记在<Party type="Supplier"> 内 - 其余标记将保持不变。
<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>
任何帮助将不胜感激
谢谢
【问题讨论】: