XPath and XSLT code tips
You can improve message flow performance with XPath and XSLT by using some optimization techniques.
Before you begin
Read the following topics:
About this task
You can improve the performance of XPath by explicitly
specifying the number of instances that are required. For example:
/element[1]
finds the first occurrence of the element and then stops/element[2]
finds the second occurrence of the element and then stops/element
returns a node set of all instances in the message, which involves a full parse of the message
For more information about techniques that you can use to optimize your XML code, see Top 10 tips for using XPath.
XSLT has advantages in terms of its potential for code reuse, and caching is available for loaded stylesheets in IBM Integration Bus. However, the stylesheet requires a BLOB as input and produces a BLOB as output, and it is less efficient than ESQL and Java™ in terms of interaction with the message tree. When it is used mid-stream with other IBM Integration Bus technologies, it results in increased message parsing and serialization.
You
can optimize the performance of your XSLT code by using a templates
object (with different transformers for each transformation) to do
multiple transformations with the same set of stylesheet instructions.
You can also improve the efficiency of your stylesheets, by using
the following techniques:
- Use
xsl:key
elements and thekey()
function as an efficient way to retrieve node sets - Where possible, use pattern matching rather than
xsl:if
orxsl:when
statements - Avoid the use of
"//"
(descendant axes) patterns near the root of a large document
Also consider the following points:
- When you are creating variables,
<xsl:variable name="abcElem" select="abc"/>
is usually faster than<xsl:variable name="abcElem"><xsl:value-of-select="abc"/></xsl:variable>
xsl:for-each
is fast because it does not require pattern matchingxsl:sort
prevents incremental processing- Use of index predicates within match patterns can be costly in terms of performance
- Decoding and encoding are costly in terms of performance
- If the XSLT is cached, the performance is improved because the XSLT is not parsed every time it is used; for more information, see XSLTransform node