p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   Replacing New Root Node (http://p2p.wrox.com/showthread.php?t=48718)

fauster October 6th, 2006 09:41 AM

Replacing New Root Node
 
I have the following XML document:

<fxEnvelope>
  <header>
    <message>
      <exchangeID>ForestExpress</exchangeID>
      <messageID>PPB54706959</messageID>
      <arrivalTime>2006-08-25T18:19:05GMT</arrivalTime>
      <subject>Order</subject>
      <payloadType>X</payloadType>
    </message>
    <from>
      <orgID>xpx001</orgID>
      <messageID>84-P17871_119017</messageID>
    </from>
    <to>
      <orgID>apl002</orgID>
    </to>
  </header>
  <body><Order>
      <OrderHeader>
        <OrderNumber>
          <BuyerOrderNumber>84-P17871</BuyerOrderNumber>
        </OrderNumber>
        <OrderIssueDate>20060825T00:00:00</OrderIssueDate>
        <OrderReferences>
          <OtherOrderReferences>
            <ListOfReferenceCoded>
              <ReferenceCoded>
                <ReferenceTypeCoded>TrackingNumber</ReferenceTypeCoded>
                <PrimaryReference>
                  <Reference>
                    <RefNum>119017</RefNum>
                  </Reference>
                </PrimaryReference>
              </ReferenceCoded>
              <ReferenceCoded>
                <ReferenceTypeCoded>PurchaseOrderNumber</ReferenceTypeCoded>
                <PrimaryReference>
                  <Reference>
                    <RefNum>84-P17871</RefNum>
                  </Reference>
                </PrimaryReference>
              </ReferenceCoded>
              <ReferenceCoded>
                <ReferenceTypeCoded>Other</ReferenceTypeCoded>
                <ReferenceTypeCodedOther>XpedxLegacyVendorNumber </ReferenceTypeCodedOther>
                <PrimaryReference>
                  <Reference>
                    <RefNum>103012</RefNum>
                  </Reference>
                </PrimaryReference>
              </ReferenceCoded>
            </ListOfReferenceCoded>
          </OtherOrderReferences>
        </OrderReferences>
        <Purpose>
          <PurposeCoded>Original</PurposeCoded>
        </Purpose>
        <OrderType>
          <OrderTypeCoded>DirectShip</OrderTypeCoded>
        </OrderType>
        <OrderCurrency>
          <Currency>
            <CurrencyCoded>USD</CurrencyCoded>
          </Currency>
        </OrderCurrency>
        <OrderLanguage>
          <Language>
            <LanguageCoded>en</LanguageCoded>
          </Language>
        </OrderLanguage>
        <OrderDates>
          <RequestedDeliverByDate>20060829T00:00:00</RequestedDeliverByDate>
        </OrderDates>
        <OrderParty>
          <BuyerParty>
            <Party>
              <PartyID>
                <Identifier>
                  <Agency>
                    <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded>
                  </Agency>
                  <Ident>0024665550000</Ident>
                </Identifier>
              </PartyID>
              <NameAddress>
                <Name1>xpedx - Syracuse</Name1>
                <Street>6485 Ridings Rd</Street>
                <StreetSupplement1></StreetSupplement1>
                <PostalCode>13206-0000</PostalCode>
                <City>SYRACUSE</City>
                <Region>
                  <RegionCoded>USNY</RegionCoded>
                </Region>
                <Country>
                  <CountryCoded>US</CountryCoded>
                </Country>
              </NameAddress>
              <OrderContact>
                <Contact>
                  <ContactName>Michele Sidello LPC-Syracuse </ContactName>
                  <ListOfContactNumber>
                    <ContactNumber>
                      <ContactNumberValue>3154329949</ContactNumberValue>
                      <ContactNumberTypeCoded>FaxNumber</ContactNumberTypeCoded>
                    </ContactNumber>
                  </ListOfContactNumber>
                </Contact>
              </OrderContact>
            </Party>
          </BuyerParty>
          <SellerParty>
            <Party>
              <PartyID>
                <Identifier>
                  <Agency>
                    <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded>
                  </Agency>
                  <Ident>apl002 </Ident>
                </Identifier>
              </PartyID>
            </Party>
          </SellerParty>
          <ShipToParty>
            <Party>
              <PartyID>
                <Identifier>
                  <Agency>
                    <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded>
                  </Agency>
                  <Ident>80840008411679000001</Ident>
                </Identifier>
              </PartyID>
              <NameAddress>
                <Name1>SYRACUSE UNIV PRINTING SVCS</Name1>
                <Street>HAWKINS BUILDING</Street>
                <StreetSupplement1>1600 JAMESVILLE AVE</StreetSupplement1>
                <PostalCode>13244</PostalCode>
                <City>SYRACUSE</City>
                <Region>
                  <RegionCoded>USNY</RegionCoded>
                </Region>
                <Country>
                  <CountryCoded>US</CountryCoded>
                </Country>
              </NameAddress>
              <OrderContact>
                <Contact>
                  <ContactName></ContactName>
                </Contact>
              </OrderContact>
            </Party>
          </ShipToParty>
          <BillToParty>
            <Party>
              <PartyID>
                <Identifier>
                  <Agency>
                    <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded>
                  </Agency>
                  <Ident>0030276040000</Ident>
                </Identifier>
              </PartyID>
              <NameAddress>
                <Name1>xpedx/Syracuse</Name1>
                <Street>SEND INVOICES TO: P.O. BOX 1337</Street>
                <StreetSupplement1></StreetSupplement1>
                <PostalCode>171051337</PostalCode>
                <City>HARRISBURG</City>
                <Region>
                  <RegionCoded>USPA</RegionCoded>
                </Region>
                <Country>
                  <CountryCoded>US</CountryCoded>
                </Country>
              </NameAddress>
            </Party>
          </BillToParty>
        </OrderParty>
        <ListOfTransport>
          <Transport>
            <TransportID>1</TransportID>
            <TransportMode>
              <TransportModeCoded>BestWay-ShippersOption</TransportModeCoded>
            </TransportMode>
          </Transport>
        </ListOfTransport>
        <OrderTermsOfDelivery>
          <TermsOfDelivery>
            <TermsOfDeliveryFunctionCoded>DeliveryCondition</TermsOfDeliveryFunctionCoded>
            <ShipmentMethodOfPaymentCoded>DefinedByBuyerAndSel ler</ShipmentMethodOfPaymentCoded>
            <Location>
              <LocationQualifierCoded>Other</LocationQualifierCoded>
              <LocationIdentifier>
                <LocID>
                  <Identifier>
                    <Agency>
                      <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded>
                    </Agency>
                    <Ident>N/A</Ident>
                  </Identifier>
                </LocID>
              </LocationIdentifier>
            </Location>
          </TermsOfDelivery>
        </OrderTermsOfDelivery>
        <OrderHeaderNote>ship all from wisconsin direct please reference customer purchase order k112785 ref 26138 price quoted by Barb plus 75.00 freight chge</OrderHeaderNote>
      </OrderHeader>
      <OrderDetail>
        <ListOfItemDetail>
          <ItemDetail>
            <BaseItemDetail>
              <LineItemNum>
                <BuyerLineItemNum>0100</BuyerLineItemNum>
              </LineItemNum>
              <LineItemType>
                <LineItemTypeCoded>Other</LineItemTypeCoded>
                <LineItemTypeCodedOther>Direct</LineItemTypeCodedOther>
              </LineItemType>
              <ItemIdentifiers>
                <PartNumbers>
                  <BuyerPartNumber>
                    <PartNum>
                      <PartID>2199069</PartID>
                    </PartNum>
                  </BuyerPartNumber>
                  <ManufacturerPartNumber>
                    <PartID>1294</PartID>
                  </ManufacturerPartNumber>
                </PartNumbers>
                <ItemDescription>APPLETON RADIANT FLUO C1S 10pt 8.5&quot;x 11&quot; 29M PEACH</ItemDescription>
              </ItemIdentifiers>
              <TotalQuantity>
                <Quantity>
                  <QuantityValue>1</QuantityValue>
                  <UnitOfMeasurement>
                    <UOMCoded>CT</UOMCoded>
                  </UnitOfMeasurement>
                </Quantity>
              </TotalQuantity>
            </BaseItemDetail>
            <PricingDetail>
              <ListOfPrice>
                <Price>
                  <UnitPrice>
                    <UnitPriceValue>220.4</UnitPriceValue>
                    <UnitOfMeasurement>
                      <UOMCoded>HW</UOMCoded>
                    </UnitOfMeasurement>
                  </UnitPrice>
                </Price>
              </ListOfPrice>
            </PricingDetail>
            <DeliveryDetail>
              <ListOfScheduleLine>
                <ScheduleLine>
                  <Quantity>
                    <QuantityValue>1</QuantityValue>
                    <UnitOfMeasurement>
                      <UOMCoded>CT</UOMCoded>
                    </UnitOfMeasurement>
                  </Quantity>
                </ScheduleLine>
              </ListOfScheduleLine>
            </DeliveryDetail>
            <LineItemNote></LineItemNote>
          </ItemDetail>
          <ItemDetail>
            <BaseItemDetail>
              <LineItemNum>
                <BuyerLineItemNum>0110</BuyerLineItemNum>
              </LineItemNum>
              <LineItemType>
                <LineItemTypeCoded>Other</LineItemTypeCoded>
                <LineItemTypeCodedOther>Direct</LineItemTypeCodedOther>
              </LineItemType>
              <ItemIdentifiers>
                <PartNumbers>
                  <BuyerPartNumber>
                    <PartNum>
                      <PartID>2199069</PartID>
                    </PartNum>
                  </BuyerPartNumber>
                  <ManufacturerPartNumber>
                    <PartID>1294</PartID>
                  </ManufacturerPartNumber>
                </PartNumbers>
                <ItemDescription>APPLETON RADIANT FLUO C1S 10pt 8.5&quot;x 11&quot; 29M PEACH</ItemDescription>
              </ItemIdentifiers>
              <TotalQuantity>
                <Quantity>
                  <QuantityValue>1</QuantityValue>
                  <UnitOfMeasurement>
                    <UOMCoded>CT</UOMCoded>
                  </UnitOfMeasurement>
                </Quantity>
              </TotalQuantity>
            </BaseItemDetail>
            <PricingDetail>
              <ListOfPrice>
                <Price>
                  <UnitPrice>
                    <UnitPriceValue>220.4</UnitPriceValue>
                    <UnitOfMeasurement>
                      <UOMCoded>HW</UOMCoded>
                    </UnitOfMeasurement>
                  </UnitPrice>
                </Price>
              </ListOfPrice>
            </PricingDetail>
            <DeliveryDetail>
              <ListOfScheduleLine>
                <ScheduleLine>
                  <Quantity>
                    <QuantityValue>1</QuantityValue>
                    <UnitOfMeasurement>
                      <UOMCoded>CT</UOMCoded>
                    </UnitOfMeasurement>
                  </Quantity>
                </ScheduleLine>
              </ListOfScheduleLine>
            </DeliveryDetail>
            <LineItemNote>COST $220.40/CWT PLUS FREIGHT CHGE OF $75.00 INCLUDED IN THE RESALE REFERENCE CUSTOMER PO# K112785 REF# 26138</LineItemNote>
          </ItemDetail>
        </ListOfItemDetail>
      </OrderDetail>
      <OrderSummary>
        <NumberOfLines>2</NumberOfLines>
        <TotalAmount>
          <MonetaryValue>
            <MonetaryAmount>204.54</MonetaryAmount>
          </MonetaryValue>
        </TotalAmount>
      </OrderSummary>
    </Order></body>
</fxEnvelope>

I am trying to extract only the <Order> to </Order> portion and adding a namespace tag to the <Order>. I am using the following XSLT:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="rrn:org.xcbl:schemas/xcbl/v3_0/xcbl30.xsd">

<xsl:template match="Order">
<Order>
          <xsl:copy-of select="."/>
</Order>
 </xsl:template>

 <xsl:template match="message | from | to" />

 </xsl:stylesheet>

I get the following output when using the current XSLT:

<?xml version="1.0"?>
<Order xmlns="rrn:org.xcbl:schemas/xcbl/v3_0/xcbl30.xsd">
<Order xmlns="">
<OrderHeader>
<OrderNumber>
<BuyerOrderNumber>84-P17871</BuyerOrderNumber>
</OrderNumber>
<OrderIssueDate>20060825T00:00:00</OrderIssueDate>
<OrderReferences>
<OtherOrderReferences>
<ListOfReferenceCoded>
<ReferenceCoded>
<ReferenceTypeCoded>TrackingNumber</ReferenceTypeCoded>
<PrimaryReference>
<Reference>
<RefNum>119017</RefNum>
</Reference>
</PrimaryReference>
</ReferenceCoded>
<ReferenceCoded>
<ReferenceTypeCoded>PurchaseOrderNumber</ReferenceTypeCoded>
<PrimaryReference>
<Reference>
<RefNum>84-P17871</RefNum>
</Reference>
</PrimaryReference>
</ReferenceCoded>
<ReferenceCoded>
<ReferenceTypeCoded>Other</ReferenceTypeCoded>
<ReferenceTypeCodedOther>XpedxLegacyVendorNumber </ReferenceTypeCodedOther>
<PrimaryReference>
<Reference>
<RefNum>103012</RefNum>
</Reference>
</PrimaryReference>
</ReferenceCoded>
</ListOfReferenceCoded>
</OtherOrderReferences>
</OrderReferences>
<Purpose>
<PurposeCoded>Original</PurposeCoded>
</Purpose>
<OrderType>
<OrderTypeCoded>DirectShip</OrderTypeCoded>
</OrderType>
<OrderCurrency>
<Currency>
<CurrencyCoded>USD</CurrencyCoded>
</Currency>
</OrderCurrency>
<OrderLanguage>
<Language>
<LanguageCoded>en</LanguageCoded>
</Language>
</OrderLanguage>
<OrderDates>
<RequestedDeliverByDate>20060829T00:00:00</RequestedDeliverByDate>
</OrderDates>
<OrderParty>
<BuyerParty>
<Party>
<PartyID>
<Identifier>
<Agency>
<AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded>
</Agency>
<Ident>0024665550000</Ident>
</Identifier>
</PartyID>
<NameAddress>
<Name1>xpedx - Syracuse</Name1>
<Street>6485 Ridings Rd</Street>
<StreetSupplement1></StreetSupplement1>
<PostalCode>13206-0000</PostalCode>
<City>SYRACUSE</City>
<Region>
<RegionCoded>USNY</RegionCoded>
</Region>
<Country>
<CountryCoded>US</CountryCoded>
</Country>
</NameAddress>
<OrderContact>
<Contact>
<ContactName>Michele Sidello LPC-Syracuse </ContactName>
<ListOfContactNumber>
<ContactNumber>
<ContactNumberValue>3154329949</ContactNumberValue>
<ContactNumberTypeCoded>FaxNumber</ContactNumberTypeCoded>
</ContactNumber>
</ListOfContactNumber>
</Contact>
</OrderContact>
</Party>
</BuyerParty>
<SellerParty>
<Party>
<PartyID>
<Identifier>
<Agency>
<AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded>
</Agency>
<Ident>apl002 </Ident>
</Identifier>
</PartyID>
</Party>
</SellerParty>
<ShipToParty>
<Party>
<PartyID>
<Identifier>
<Agency>
<AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded>
</Agency>
<Ident>80840008411679000001</Ident>
</Identifier>
</PartyID>
<NameAddress>
<Name1>SYRACUSE UNIV PRINTING SVCS</Name1>
<Street>HAWKINS BUILDING</Street>
<StreetSupplement1>1600 JAMESVILLE AVE</StreetSupplement1>
<PostalCode>13244</PostalCode>
<City>SYRACUSE</City>
<Region>
<RegionCoded>USNY</RegionCoded>
</Region>
<Country>
<CountryCoded>US</CountryCoded>
</Country>
</NameAddress>
<OrderContact>
<Contact>
<ContactName></ContactName>
</Contact>
</OrderContact>
</Party>
</ShipToParty>
<BillToParty>
<Party>
<PartyID>
<Identifier>
<Agency>
<AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded>
</Agency>
<Ident>0030276040000</Ident>
</Identifier>
</PartyID>
<NameAddress>
<Name1>xpedx/Syracuse</Name1>
<Street>SEND INVOICES TO: P.O. BOX 1337</Street>
<StreetSupplement1></StreetSupplement1>
<PostalCode>171051337</PostalCode>
<City>HARRISBURG</City>
<Region>
<RegionCoded>USPA</RegionCoded>
</Region>
<Country>
<CountryCoded>US</CountryCoded>
</Country>
</NameAddress>
</Party>
</BillToParty>
</OrderParty>
<ListOfTransport>
<Transport>
<TransportID>1</TransportID>
<TransportMode>
<TransportModeCoded>BestWay-ShippersOption</TransportModeCoded>
</TransportMode>
</Transport>
</ListOfTransport>
<OrderTermsOfDelivery>
<TermsOfDelivery>
<TermsOfDeliveryFunctionCoded>DeliveryCondition</TermsOfDeliveryFunctionCoded>
<ShipmentMethodOfPaymentCoded>DefinedByBuyerAndSel ler</ShipmentMethodOfPaymentCoded>
<Location>
<LocationQualifierCoded>Other</LocationQualifierCoded>
<LocationIdentifier>
<LocID>
<Identifier>
<Agency>
<AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded>
</Agency>
<Ident>N/A</Ident>
</Identifier>
</LocID>
</LocationIdentifier>
</Location>
</TermsOfDelivery>
</OrderTermsOfDelivery>
<OrderHeaderNote>ship all from wisconsin direct please reference customer purchase order k112785 ref 26138 price quoted by Barb plus 75.00 freight chge</OrderHeaderNote>
</OrderHeader>
<OrderDetail>
<ListOfItemDetail>
<ItemDetail>
<BaseItemDetail>
<LineItemNum>
<BuyerLineItemNum>0100</BuyerLineItemNum>
</LineItemNum>
<LineItemType>
<LineItemTypeCoded>Other</LineItemTypeCoded>
<LineItemTypeCodedOther>Direct</LineItemTypeCodedOther>
</LineItemType>
<ItemIdentifiers>
<PartNumbers>
<BuyerPartNumber>
<PartNum>
<PartID>2199069</PartID>
</PartNum>
</BuyerPartNumber>
<ManufacturerPartNumber>
<PartID>1294</PartID>
</ManufacturerPartNumber>
</PartNumbers>
<ItemDescription>APPLETON RADIANT FLUO C1S 10pt 8.5"x 11" 29M PEACH</ItemDescription>
</ItemIdentifiers>
<TotalQuantity>
<Quantity>
<QuantityValue>1</QuantityValue>
<UnitOfMeasurement>
<UOMCoded>CT</UOMCoded>
</UnitOfMeasurement>
</Quantity>
</TotalQuantity>
</BaseItemDetail>
<PricingDetail>
<ListOfPrice>
<Price>
<UnitPrice>
<UnitPriceValue>220.4</UnitPriceValue>
<UnitOfMeasurement>
<UOMCoded>HW</UOMCoded>
</UnitOfMeasurement>
</UnitPrice>
</Price>
</ListOfPrice>
</PricingDetail>
<DeliveryDetail>
<ListOfScheduleLine>
<ScheduleLine>
<Quantity>
<QuantityValue>1</QuantityValue>
<UnitOfMeasurement>
<UOMCoded>CT</UOMCoded>
</UnitOfMeasurement>
</Quantity>
</ScheduleLine>
</ListOfScheduleLine>
</DeliveryDetail>
<LineItemNote></LineItemNote>
</ItemDetail>
<ItemDetail>
<BaseItemDetail>
<LineItemNum>
<BuyerLineItemNum>0110</BuyerLineItemNum>
</LineItemNum>
<LineItemType>
<LineItemTypeCoded>Other</LineItemTypeCoded>
<LineItemTypeCodedOther>Direct</LineItemTypeCodedOther>
</LineItemType>
<ItemIdentifiers>
<PartNumbers>
<BuyerPartNumber>
<PartNum>
<PartID>2199069</PartID>
</PartNum>
</BuyerPartNumber>
<ManufacturerPartNumber>
<PartID>1294</PartID>
</ManufacturerPartNumber>
</PartNumbers>
<ItemDescription>APPLETON RADIANT FLUO C1S 10pt 8.5"x 11" 29M PEACH</ItemDescription>
</ItemIdentifiers>
<TotalQuantity>
<Quantity>
<QuantityValue>1</QuantityValue>
<UnitOfMeasurement>
<UOMCoded>CT</UOMCoded>
</UnitOfMeasurement>
</Quantity>
</TotalQuantity>
</BaseItemDetail>
<PricingDetail>
<ListOfPrice>
<Price>
<UnitPrice>
<UnitPriceValue>220.4</UnitPriceValue>
<UnitOfMeasurement>
<UOMCoded>HW</UOMCoded>
</UnitOfMeasurement>
</UnitPrice>
</Price>
</ListOfPrice>
</PricingDetail>
<DeliveryDetail>
<ListOfScheduleLine>
<ScheduleLine>
<Quantity>
<QuantityValue>1</QuantityValue>
<UnitOfMeasurement>
<UOMCoded>CT</UOMCoded>
</UnitOfMeasurement>
</Quantity>
</ScheduleLine>
</ListOfScheduleLine>
</DeliveryDetail>
<LineItemNote>COST $220.40/CWT PLUS FREIGHT CHGE OF $75.00 INCLUDED IN THE RESALE REFERENCE CUSTOMER PO# K112785 REF# 26138</LineItemNote>
</ItemDetail>
</ListOfItemDetail>
</OrderDetail>
<OrderSummary>
<NumberOfLines>2</NumberOfLines>
<TotalAmount>
<MonetaryValue>
<MonetaryAmount>204.54</MonetaryAmount>
</MonetaryValue>
</TotalAmount>
</OrderSummary>
</Order>
</Order>

How can I eliminate the duplicate <Order> </Order> tags while preserving the namespace that is added to the root <Order> tag?




joefawcett October 6th, 2006 10:06 AM

Do you want all the elements underneath the new Order root to be in the same namespace as Order?


--

Joe (Microsoft MVP - XML)

fauster October 6th, 2006 10:29 AM

Yes, but I only need the namespace specified within the <Order> tag.


joefawcett October 6th, 2006 10:49 AM

As you don't have any attributes to worry about, nor mixed content, the following should work;
Code:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <xsl:apply-templates select="/*/body/Order"/>
  </xsl:template>
  <xsl:template match="Order">
    <Order xmlns="rrn:org.xcbl:schemas/xcbl/v3_0/xcbl30.xsd">
      <xsl:apply-templates/>
    </Order>
  </xsl:template>
  <xsl:template match="Order//*">
    <xsl:element name="{local-name()}" namespace="rrn:org.xcbl:schemas/xcbl/v3_0/xcbl30.xsd">
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

I think Michael Kay could produce amore elegant and robust version though.

--

Joe (Microsoft MVP - XML)

fauster October 6th, 2006 11:17 AM

Works great! I would like to understand a couple of things, however.

1. So the select="/*/body/Order"/ extracts beginning only at <Order>?

2. The template match="Order//*" - what is that communicating? Does it extract only the <Order> tag with the namespace and remove the second <Order> tag that is created?

Thanks for your help.



All times are GMT -4. The time now is 07:48 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.