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 March 20th, 2007, 05:03 AM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default I need help with xslt?????

Hi there xslt gurus,
i am kinda new to xslt and having difficulty to implement my some iterations. i need to recreate an xml file by using xslt. here is the sample xml file(input for xslt)

<Flights>
 <Flight>
   <FlightLeg >
     <BookingClassCodeList>
       <BookingCode Value="C" />
       <BookingCode Value="Y" />
     </BookingClassCodeList>
   </FlightLeg>
  </Flight>
  <Flight>
   <FlightLeg >
     <BookingClassCodeList>
       <BookingCode Value="C" />
     </BookingClassCodeList>
   </FlightLeg>
   <FlightLeg >
     <BookingClassCodeList>
       <BookingCode Value="A" />
       <BookingCode Value="B" />
     </BookingClassCodeList>
   </FlightLeg>
  </Flight>
<Flights>
AS you can see, there can be 1 or more flightlegs per flight. I need to do sth by xslt so that:
- instead of first flight node there will be 2 new flight nodes with bookingclasscode values are assigned as attribute to flightleg
 <Flight>
   <FlightLeg booking="C" />
  </Flight>
  <Flight>
   <FlightLeg booking="Y" />
  </Flight>
-- and instead of second flight node there will be 2 new flight nodes(combination of booking classes of flightlegs) with related attributes assigned
 <Flight>
   <FlightLeg booking="C" />
   <FlightLeg booking="A" />
  </Flight>
<Flight>
   <FlightLeg booking="C" />
   <FlightLeg booking="B" />
  </Flight>

I feel like this can be implemented by xslt since it is recursive based programming, but i couldn't figure it out. If you can help me i really appreciate it. thanks in advance!

 
Old March 20th, 2007, 06:50 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

I am not sure I completely understand your what you need, but I gave it a shot:

[code]<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="fn xs">
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/Flights">
        <Flights>
            <xsl:for-each select="Flight">
                <Flight>
                    <xsl:for-each select="FlightLeg">
                        <xsl:for-each select="BookingClassCodeList">
                            <xsl:for-each select="BookingCode">
                                <FlightLeg>
                                    <xsl:for-each select="@Value">
                                        <xsl:attribute name="booking">
                                            <xsl:value-of select="xs:string( . )"/>
                                        </xsl:attribute>
                                    </xsl:for-each>
                                </FlightLeg>
                            </xsl:for-each>
                        </xsl:for-each>
                    </xsl:for-each>
                </Flight>
            </xsl:for-each>
        </Flights>
    </xsl:template>
</xsl:stylesheet>[code]
 
Old March 20th, 2007, 07:16 AM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thx for your quick response bonekrusher, but it loses soma data. I mean it has to calculate all combinations per booking class and per leg. That is,

if there are 3 flightLegs for a flight:

leg1{A, B, C} // 3 booking class codes for leg1
leg2{A, Y} // 2 booking class codes for leg2
leg 3{E,F,G} // 3 booking class codes for leg3

then in new xml file, there must be 3 x 2 x 3 = 18 new flight elements
3 example of newly created 18 flight nodes

<Flight>
   <FlightLeg booking="A" />
   <FlightLeg booking="A" />
   <FlightLeg booking="E" />
  </Flight>
<Flight>
   <FlightLeg booking="A" />
   <FlightLeg booking="A" />
   <FlightLeg booking="F" />
</Flight>
<Flight>
   <FlightLeg booking="B" />
   <FlightLeg booking="Y" />
   <FlightLeg booking="F" />
</Flight>
... and so on..am i more clear now?

 
Old March 20th, 2007, 06:36 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

no not really. Do me a favor. Post a new input XML. Then show desired result. Make sure its exacly like you want it.

Your example above shows leg1{A, B, C} but the desire results do not have the same attributes..e.g. you show the first flight with 3 legs "A,A,E' in your desired results.

maybe I am missing something.








Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating XSLT with XSLT stonis XSLT 3 April 1st, 2008 08:17 PM
General XSLT Questions in the XSLT Forum jminatel BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 0 March 31st, 2008 07:50 PM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
xslt with an xslt outputfile alleycat XSLT 4 February 20th, 2006 09:56 AM





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