Project

Profile

Help

Java Xslt Function Performance

Added by Anonymous over 15 years ago

Legacy ID: #5968987 Legacy Poster: ngeren (ngeren)

Hi, I'm attempting to port over an existing XSLT function from a different implementation which uses embedded XPath on the provided argument (XML node). I've been able to get this working with Saxon, however am encountering some performance problems (awfully slow). If there are better ways of implementing this and/or methods, I'm all for them. I've tried implementing the logic in straight XSLT, but the logic gets hairy debugging. Examples of both the source XML and XSLT Java function are below. The goal of the logic ultimately is to find the "element" node that contains the most current start date, depicted by the date in element[@Id="DTP03"] (If that makes sense). Any help would be greatly appreciated! The core/skeleton of my implementation is below: public class TestFunction { XPathEvaluator xpathEval; XPathExpression xpathExpr; public TestFunction() { xpathEval = new XPathEvaluator(); xpathExpr = xpathEval.createExpression("//segment[@Id=&quot;DTP&quot; and child::element[@Id=&quot;DTP01&quot;]/text() = &quot;348&quot;]/element[@Id=&quot;DTP03&quot;]"); } public String execute(TinyNodeImpl node) { if (node != null) { TinyNodeImpl dtp03 = (TinyNodeImpl)xpathExpr.evaluateSingle(loopElement); // ... perform further logic (including additional Xpath operations) } } } The source XML structure looks like: <loop Id="2100"> <segment Id="HD"> <element Id="HD01">00</element> <!-- ... ---> </segment> <segment Id="DTP"> <element Id="DTP01">348</element> <element Id="DTP02">12</element> <element Id="DTP03">2008-12-23</element> </segment> <segment Id="DTP"> <element Id="DTP01">349</element> <element Id="DTP02">12</element> <element Id="DTP03">2008-12-23</element> </segment> </loop> <loop Id="2100"> <segment Id="HD"> <element Id="HD01">00</element> <!-- ... ---> </segment> <segment Id="DTP"> <element Id="DTP01">348</element> <element Id="DTP02">12</element> <element Id="DTP03">2009-01-01</element> </segment> <segment Id="DTP"> <element Id="DTP01">349</element> <element Id="DTP02">12</element> <element Id="DTP03">2009-01-01</element> </segment> </loop>


Replies (1)

RE: Java Xslt Function Performance - Added by Anonymous over 15 years ago

Legacy ID: #5969852 Legacy Poster: Michael Kay (mhkay)

I don't think I understand the scenario well enough. Are you creating TestFunction() once and then calling execute() repeatedly? Have you pinned down where the time is being spent, e.g. do you know that it is in the xpathExpr.evaluateSingle() call that you have shown? How big is the source document? If you're calling this from XSLT then I'm a little surprised that it works at all, because the XPathEvaluator is not using the same Saxon Configuration as was used to create the Node being processed. From what you've shown, I can't see any good reason for not doing this logic at the XSLT level. Apart from anything else, you could then use keys.

    (1-1/1)

    Please register to reply