XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Bob WhittySubject: XML to XML Transformation
Author: Bob Whitty
Date: 29 Apr 2010 11:28 AM
Hi Folks -

I'm converting an inbound XML document into a resulting XML document I can use to import into SQL Server 2005. I'm attempting to output the Carrier element in the transformation under a different element name (OtherPartner) with a PartnerRole attribute = 'Carrier'. Thus far all my attempts have failed and the Carrier element seems to be ignored. I'm wondering if someone could tell me what it is I'm doing wrong.

Inbound document fragment:
(FromID & DocID are global variables)

< ShipmentStatusPartners >
< Carrier >
< PartnerInformation >
< PartnerName >Whiz Bang Trucking< /PartnerName >
< PartnerIdentifier Agency="GLN" >NA< /PartnerIdentifier >
< /PartnerInformation >
< /Carrier >
< OtherPartner PartnerRole="ShipFrom" >
< PartnerInformation >
< PartnerName >Ship Plant< /PartnerName >
< PartnerIdentifier Agency="GLN" >0000000000000< /PartnerIdentifier >
< /PartnerInformation >
< /OtherPartner >
< OtherPartner PartnerRole="ShipTo" >
< PartnerInformation >
< PartnerName >RECIPIENT TERMINAL< /PartnerName >
< PartnerIdentifier Agency="GLN" >0000000000000< /PartnerIdentifier >
< /PartnerInformation >
< /OtherPartner >
< /ShipmentStatusPartners >

Expected transformed document:
<ShipmentStatusPartners>
<FromID>0811875010007</FromID>
<DocID>7031081</DocID>
<OtherPartner PartnerRole="Carrier">
<PartnerInformation>
<PartnerName>Whiz Bang Trucking</PartnerName>
<PartnerIdentifier Agency="GLN">0000000000000</PartnerIdentifier>
</PartnerInformation>
</OtherPartner>
<OtherPartner PartnerRole="ShipFrom">
<PartnerInformation>
<PartnerName>Ship Plant</PartnerName>
<PartnerIdentifier Agency="GLN">0000000000000</PartnerIdentifier>
</PartnerInformation>
</OtherPartner>
<OtherPartner PartnerRole="ShipTo">
<PartnerInformation>
<PartnerName>RECIPIENT TERMINAL</PartnerName>
<PartnerIdentifier Agency="GLN">0000000000000</PartnerIdentifier>
</PartnerInformation>
</OtherPartner>
</ShipmentStatusPartners>

Dubious XSLT:
< xsl:template match="ShipmentStatusBody/ShipmentStatusPartners" >
< xsl:element name="ShipmentStatusBody" >
< xsl:element name="ShipmentStatusPartners" >
< xsl:element name="FromID" >
< xsl:apply-templates select="$FromID"/ >
< /xsl:element >
< xsl:element name="DocID" >
< xsl:apply-templates select="$DocID"/ >
< /xsl:element >
< xsl:choose >
< xsl:when test="self::Carrier" >
< xsl:element name="OtherPartner" >
< xsl:attribute name="PartnerRole" >
< xsl:value-of select=" 'Carrier' "/ >
< /xsl:attribute >
< /xsl:element >
< xsl:element name="PartnerInformation" >
< xsl:element name="PartnerName" >
< xsl:copy >
< xsl:value-of select="./ShipmentStatusPartners/Carrier/PartnerInformation/PartnerName"/ >
< /xsl:copy >
< /xsl:element >
< xsl:element name="PartnerIdentifier" >
< xsl:copy >
< xsl:value-of select="./ShipmentStatusPartners/Carrier/PartnerInformation/PartnerIdentifier"/ >
< /xsl:copy >
< /xsl:element >
< /xsl:element >
< /xsl:when >
< xsl:otherwise >
< xsl:copy-of select="//OtherPartner"/ >
< /xsl:otherwise >
< /xsl:choose >
< /xsl:element >
< /xsl:element >
< /xsl:template >

Thanks for giving it a look!

Bob

Postnext
(Deleted User) Subject: XML to XML Transformation
Author: (Deleted User)
Date: 30 Apr 2010 12:45 PM
Hi Bob,
you shouldn't use the "self" axis when testing for Carrier, as the context node is the one specified in the match expression of the template. You should use either child::Carrier or just "./Carrier" like you do in the next lines.

Alberto

Posttop
Bob WhittySubject: XML to XML Transformation
Author: Bob Whitty
Date: 01 May 2010 12:23 PM
Thanks Alberto!

I really appreciate you taking the time to give it a look and respond. I'll give it a go and I'm sure it will work out fine - this old dog is still trying to learn some new tricks!

Bob

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.