1
我想將2-3個xml文件合併到一個文件中供我的系統處理。我回顧了其他幾篇文章,並得出了我認爲可以使用文檔的代碼,但似乎並沒有達到預期的效果。我是一個真正的新手,所以在這方面的幫助真的很感謝。我的方案代碼:使用XSL合併多個xml文件
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/OrderRequest">
<xsl:copy>
<xsl:apply-templates select="OrderRequest"/>
<xsl:apply-templates select="document('2.xml')/*/OrderRequest"/>
<xsl:apply-templates select="document('3.xml')/*/OrderRequest"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
這裏是我的xml文件的結構的樣品。數據,但所有的數據很多,我需要OrderRequest
下<cXML xml:lang="en-US" payloadID="2015-11-06Orders" timestamp="2015-11-06T13:30:11-05:00">
<Header>
<From>
<Credential domain="NetworkId">
<Identity>Order Admin</Identity>
</Credential>
</From>
<To>
<Credential domain="NetworkId">
<Identity>fulfillment</Identity>
</Credential>
</To>
<Sender><Credential domain="NetworkId"><Identity>admin group</Identity><SharedSecret>hidden</SharedSecret>
</Credential>
<UserAgent>Procurement Sys</UserAgent>
</Sender>
</Header>
<Request>
<OrderRequest>
<OrderRequestHeader orderID="PO12345" orderDate="2015-11-05T13:30:44-05:00" requisitionID="">
<Total><Money currency="USD">34.00</Money>
</Total>
<Shipping>
<Money currency="USD">0.00</Money>
<Description xml:lang="en-US">Next day</Description>
</Shipping>
<Contact>
<Name xml:lang="en">Smith, Bob A.</Name>
<Phone name="default">
<TelephoneNumber>
<CountryCode isoCountryCode="US">1</CountryCode>
<AreaOrCityCode>413</AreaOrCityCode>
<Number>5551234</Number>
<Extension></Extension>
</TelephoneNumber>
</Phone>
</Contact>
</OrderRequestHeader>
<ItemOut quantity="2" lineNumber="1">
<ItemID>
<SupplierPartID>TEX TI30XIIS</SupplierPartID>
</ItemID>
<ItemDetail>
<UnitPrice>
<Money currency="USD">17.00</Money></UnitPrice>
<Description xml:lang="en">Scientific Calculator, Dual Power,2Line, 3-1/5"x6-1/10"x3/4"</Description>
<UnitOfMeasure>EA</UnitOfMeasure>
<Classification domain="UNSPSC">44120000</Classification>
</ItemDetail>
<ShipTo>
<Address isoCountryCode="US" addressID="0001">
<Name xml:lang="en">Sample Location</Name>
<PostalAddress name="default">
<DeliverTo>Smith, Bob</DeliverTo>
<DeliverTo>AR Dept.</DeliverTo>
<Street>Sample Business</Street>
<Street>101 Main St.</Street>
<City>Great Barrington</City>
<State>MA</State>
<PostalCode></PostalCode>
<Country isoCountryCode="US">United States</Country>
</PostalAddress>
<Email name="default"></Email>
<Phone name="default">
<TelephoneNumber>
<CountryCode isoCountryCode="US">1</CountryCode>
<AreaOrCityCode></AreaOrCityCode>
<Number></Number>
<Extension></Extension>
</TelephoneNumber>
</Phone>
</Address>
</ShipTo>
<Distribution>
<Accounting name="General"></Accounting>
<Charge>
<Money currency="USD">34.00</Money>
</Charge>
</Distribution>
</ItemOut>
</OrderRequest>
</Request>
</cXML>
感謝
@DanielHaley第一次更改刪除了下面的所有嵌套信息,第二個建議擦除了所有內容,但是結束了cxml標記。 –
WJD
抱歉輸入樣本的格式讓我失望。請看我的答案。希望它有幫助! –
我的回答是否有幫助,還是您仍然有問題? –