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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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

   
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.