简体   繁体   English

Java XSL / XML JAXB

[英]Java XSL/XML JAXB

I am currently trying to create a travel itinerary which can be made up of 4 possible types. 我目前正在尝试创建可以由4种可能的类型组成的旅行路线。 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. 我将这些值从MySQL数据库加载到XML(一切正常)中,然后将使用XSL和FOP将其转换为PDF。

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 我正在尝试锻炼满足我的需求构造xml的最佳方法,基本上我希望它在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 我最好像这样构造xml并使用xsl分组进行转换吗

<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? 最好使用java / mysql整理分组或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. 这是用于获取航班详细信息的SQL,例如巡航,住宿等。

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. 在SQL编辑器(SQLYog)中,此操作返回的结果很好,在java中,带有系统输出的情况也很好,但在编组其最后一条记录时,只能适当次数地返回。 (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. 自从我做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. 将sql更改为以下内容,似乎更接近所需的结果,但未定义第二个表列的名称,将它们显示在其他表列中。

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. 如果您创建行程的第二个XML版本( /itinerary/leg/<resource> ),则因为数据结构和打印结构匹配,所以创建打印版本将更加容易。

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. SQL最有可能比XSL更好地进行分组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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