Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 23rd, 2006, 10:31 AM
Registered User
 
Join Date: Oct 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT problem

New to XSLT coding. Have a problem the clients seen they cannot fix in Oracle XML output. When LIST_MAILTO_ADDRESSES is blank, clients want values from LIST_BILLTO_ADDRESSES built into LIST_MAILTO_ADDRESSES. How would the coding be done in the XSLT reformater?
The LIST_MAILTO_ADDRESSES tags will usually have information, buy when empty, clients want to use values from LIST_BILLTO_ADDRESSES. How do I make this a conditional statement that determines that exsistance of MAILTO tags. . Problem XML:
<LIST_BILLTO_ADDRESSES>
        <G_BILLTO_ADDRESS>
         <ACCT_NUMBER>152814572</ACCT_NUMBER>
         <NAME>DESIGN CLASSICS</NAME>
         <NAME2></NAME2>
         <ADDRESS1>7725 W 26TH AVE UNIT F10 BLDG</ADDRESS1>
         <ADDRESS2></ADDRESS2>
         <CITY>HIALEAH</CITY>
         <STATE>FL</STATE>
         <POSTAL_CODE>33016</POSTAL_CODE>
         <COUNTRY></COUNTRY>
        </G_BILLTO_ADDRESS>
     </LIST_BILLTO_ADDRESSES>
     <LIST_MAILTO_ADDRESSES>
     </LIST_MAILTO_ADDRESSES>
XSLT code:
<LIST_BILLTO_ADDRESSES>
                            <xsl:for-each select="LIST_BILLTO_ADDRESSES/G_BILLTO_ADDRESS">
                                <G_BILLTO_ADDRESS>
                                    <ACCT_NUMBER>
                                        <xsl:value-of select="ACCT_NUMBER"/>
                                    </ACCT_NUMBER>
                                    <NAME>
                                        <xsl:value-of select="NAME"/>
                                    </NAME>
                                    <NAME2>
                                        <xsl:value-of select="NAME2"/>
                                    </NAME2>
                                    <ADDRESS1>
                                        <xsl:value-of select="ADDRESS1"/>
                                    </ADDRESS1>
                                    <ADDRESS2>
                                        <xsl:value-of select="ADDRESS2"/>
                                    </ADDRESS2>
                                    <CITY>
                                        <xsl:value-of select="CITY"/>
                                    </CITY>
                                    <STATE>
                                        <xsl:value-of select="STATE"/>
                                    </STATE>
                                    <POSTAL_CODE>
                                        <xsl:value-of select="POSTAL_CODE"/>
                                    </POSTAL_CODE>
                                    <CONSIGNEE>
                                        <xsl:value-of select="CONSIGNEE"/>
                                    </CONSIGNEE>
                                    <SHIPPER_REF>
                                        <xsl:value-of select="SHIPPER_REF"/>
                                    </SHIPPER_REF>
                                    <COUNTRY>
                                        <xsl:value-of select="COUNTRY"/>
                                    </COUNTRY>
                                </G_BILLTO_ADDRESS>
                            </xsl:for-each>
                        </LIST_BILLTO_ADDRESSES>
                        <LIST_MAILTO_ADDRESSES>
                            <xsl:for-each select="LIST_MAILTO_ADDRESSES/G_MAILTO_ADDRESS">
                                <G_MAILTO_ADDRESS>
                                    <ACCT_NUMBER>
                                        <xsl:value-of select="ACCT_NUMBER"/>
                                    </ACCT_NUMBER>
                                    <NAME>
                                        <xsl:value-of select="NAME"/>
                                    </NAME>
                                    <NAME2>
                                        <xsl:value-of select="NAME2"/>
                                    </NAME2>
                                    <ADDRESS1>
                                        <xsl:value-of select="ADDRESS1"/>
                                    </ADDRESS1>
                                    <ADDRESS2>
                                        <xsl:value-of select="ADDRESS2"/>
                                    </ADDRESS2>
                                    <CITY>
                                        <xsl:value-of select="CITY"/>
                                    </CITY>
                                    <STATE>
                                        <xsl:value-of select="STATE"/>
                                    </STATE>
                                    <POSTAL_CODE>
                                        <xsl:value-of select="POSTAL_CODE"/>
                                    </POSTAL_CODE>
                                    <CONSIGNEE>
                                        <xsl:value-of select="CONSIGNEE"/>
                                    </CONSIGNEE>
                                    <SHIPPER_REF>
                                        <xsl:value-of select="SHIPPER_REF"/>
                                    </SHIPPER_REF>
                                    <COUNTRY>
                                        <xsl:value-of select="COUNTRY"/>
                                    </COUNTRY>
                                </G_MAILTO_ADDRESS>
                            </xsl:for-each>
                        </LIST_MAILTO_ADDRESSES>
 
Old October 23rd, 2006, 11:09 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Firstly, these for-each loops seem incredibly verbose. As far as I can see, you've just coded the equivalent of

<xsl:copy-of select="LIST_BILLTO_ADDRESSES/G_BILLTO_ADDRESS">

in longhand.

But the code you want to write isn't a straight copy, so you may not be able to do that.

In XSLT 2.0 I'd suggest:

<xsl:template match="LIST_MAILTO_ADDRESSES">
  <xsl:for-each-group select="*, preceding-sibling::G_BILLTO_ADDRESS/*"
    group-by="node-name()">
     <xsl:copy-of select="current-group()[1]"/>
  </xsl:for-each-group>
</xsl:template>

which pairs up the child elements in the two addresses and copies the first of each pair.

It's harder to come up with a clean generic solution in 1.0, I suspect you're stuck with something like:

<xsl:template match="LIST_MAILTO_ADDRESSES">
  <xsl:variable name="B" select="preceding-sibling::BILLTO_ADDRESSES"/>
  <xsl:copy-of select="(ACCT_NUMBER | $B/ACCT_NUMBER)[last()]"/>
  <xsl:copy-of select="(NAME | $B/NAME)[last()]"/>

etc



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT problem with IE 7 asadallahi BOOK: Professional Ajax ISBN: 978-0-471-77778-6 3 April 9th, 2009 09:33 AM
xslt problem mickhughes XSLT 3 March 28th, 2008 05:09 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
XSLT problem pendyalap XSLT 4 March 24th, 2006 04:08 PM
problem with xslt superwebba BOOK: Professional Ajax ISBN: 978-0-471-77778-6 5 March 10th, 2006 01:31 AM





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