Monday, July 15, 2013

Comparison of XSLT and XQuery

Recently I am working on one project which gets involved in transforming a large XML document in Oracle SOA Suite 11g.  Initially this transformation is done using XSLT.   We did the end-to-end testing with a large payload and noticed that the XSLT transformation took the most of the message processing time.  Later someone suggests that with large payload XQuery is more efficient than XSLT.   So we decided to implement the same transformation using XQuery.   The comparison result is a bit surprise to me.  
  
<ein:ProcessRequest>
 <ein:DocumentID>4.IPM_013407</ein:DocumentID>
 <ein:InvoiceNumber>12345</ein:InvoiceNumber>
 <ein:InvoiceType>PO</ein:InvoiceType>
 <ein:InvoiceDescription>LYRECO JUN 2013</ein:InvoiceDescription>
 <ein:SupplierName>LYRECO PTY LTD</ein:SupplierName>
 <ein:SupplierSiteName>E-INVOICE</ein:SupplierSiteName>
 <ein:POInvoice>
  <ein:POInvoiceItems>
  <ein:InvoiceNo>2331940908</ein:InvoiceNo>
  <ein:Amount>195.42</ein:Amount>
  <ein:GSTAmount>17.77</ein:GSTAmount>
  <ein:InvoiceDate>2013-05-01</ein:InvoiceDate>
  <ein:Description>Some description text</ein:Description>
  <ein:Quantity>1</ein:Quantity>
  <ein:UnitPrice>195.42</ein:UnitPrice>
  <ein:ExpenseType>STATIONERY</ein:ExpenseType>
  <ein:ProjectNumber>200363</ein:ProjectNumber>
  <ein:TaskNumber>11040</ein:TaskNumber>
  <ein:ExpenditureType>Office Supplies</ein:ExpenditureType>
  </ein:POInvoiceItems>
  
  ............
  
 </ein:POInvoice> 
<ein:ProcessRequest> 

Firstly I tried the transformation of a XML message like the above but with over 2700 <POInvoiceItems> elements using XMLSpy.  The result shows XQuery is much faster than XSLT when transforming this message.   Roughly XQuery is 3~4 times faster. 

Then I put these two transformations into one Oracle SOA application respectively and invoke the application with the same large message payload.   The comparison show that under Oracle Weblogic environment there is no obvious difference between XQuery and XSLT and XSLT is even faster than XQuery.   I am not quite sure what cause the different results using XMLSpy and Oracle Weblogic.  Maybe it is related to the implementation of XQuery and XSLT enegines within XMLSpy and Oracle Weblogic.

3 comments:

  1. Interesting finding, did you tested for some other scenarios to suggest that both are same ?

    ReplyDelete
  2. Wow, i read this article and thought this cannot be the case every expert and blog has said xquery is faster and took their word for it, and this might be the case outside of Oracle Middleware, so we did a POC with a 15000 line xml, and ran through xquery and xslt and could not believe that in Oracle SOA 12c (OSB) that XSLT was faster than xquery doing the same transformation, around 25% quicker with a 15000 line xml, however when we did a 20 line xml we found that XSLT was more than 100% quicker. Amazing. Thanks for the post.

    ReplyDelete
  3. You can find some additional analysis that i did here:

    http://jtyreman.blogspot.co.uk/2017/04/xquery-vs-xpath-performance.html

    ReplyDelete