简体   繁体   中英

Java XSL/XML JAXB

I am currently trying to create a travel itinerary which can be made up of 4 possible types. These are Flights, Accommodation, Cruise and Misc (Car hire etc).

I am loading these values into an XML from a MySQL database (all fine), which will in turn be made into a PDF using XSL and FOP.

I am trying to workout what is the best way to structure the xml for my needs, basically I want it to look like this in the PDF

22NOV London to JFK
      ........
22NOV Hilton Hotel, New York
      ........
25NOV JFK to London
      .......

Am i best structuring the xml like so and using xsl grouping to transform

<itinerary>
  <flights>
      <flightDate>...</flightDate>
      ..........
  </flights>
  <accommodation>
      <accommodationDate>.....</accommodationDate>
      .........
  </accommodation>
  <cruise>......</cruise>
  .......

or like this.

<itinerary>
   <leg date ="">
     <flights>.....</flights>
     <accommodation>......</accommodation>
     <cruise>......</cruise>
     .......
  </leg>
  <leg date = "">
    ......
  </leg>

Is it best to use java / mysql to sort out the grouping or xsl? And which way is better if any? Any help is greatly appreciated, and hope this makes sense.

UPDATE:

Here is the SQL for obtaining Flights details much and such the same cruising, accommodation etc.

SELECT
    flightDate, air1.airportName, air2.airportName,
    flightNumber, departureTime, arrivalTime
FROM itinerary
LEFT JOIN flights ON flights.itineraryID = itinerary.itineraryID
LEFT JOIN airports air1 ON air1.airportID = flights.flightFrom
LEFT JOIN airports air2 ON air2.airportID = flights.flightTo
LEFT JOIN bookings ON itinerary.bookingID = bookings.bookingID
WHERE bookingRef='" + bookingRef + "'";

In the SQL editor (SQLYog) this return the results fine, in java with system outs it is fine but on marshalling its adding the last record only the appropriate number of times. (Structural issue i assume).

Real question am I best bring all the queries into one rather than four seperate as they are very similar? Using Outer/right joins etc (confused by these)?

Its been a long time since I did SQL.

Further update:

Have changed the sql to following, seems to be closer to desired results but not defining 2nd table columns name displaying them in the other tables columns.

SELECT
   flightDate, air1.airportName, air2.airportName, flightNumber,  
   departureTime, arrivalTime
FROM itinerary
LEFT OUTER JOIN
   flights ON itinerary.itineraryID = flights.itineraryID
LEFT JOIN
   airports AS air1 ON air1.airportID = flights.flightFrom
LEFT JOIN
   airports AS air2 ON air2.airportID = flights.flightTo
LEFT JOIN
   bookings ON bookings.bookingID = itinerary.bookingID
WHERE
  bookings.bookingRef = '000001'
UNION
  SELECT
    accommodationDate, accommodationName, duration, roomType, boardBasis, 
    notes
  FROM
    itinerary
  LEFT OUTER JOIN
    accommodation ON itinerary.itineraryID = accommodation.itineraryID
  LEFT JOIN
    bookings ON bookings.bookingID = itinerary.bookingID
  WHERE
    bookings.bookingRef = '000001';

Any help appreciated.

If you create the second XML version of the itinerary ( /itinerary/leg/<resource> ) it will be way easier to create the printed version because the data structure and the print structure match.

But maybe the first version is easier to create when querying the database.

In the end you need to decide which is easier to code. Most likely SQL is better at grouping than XSL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM