11 ene 2011

How to extend XSLT using built in extension functions. – Intel Software Network Blogs

XSLT 2.0 and to some extent 1.0 are powerful languages when it comes to transforming documents and even for performing some tasks. But, as is often the case, to do something odd or unusual can often be impenetrable or just plain difficult. One of the advantages of using Intel® SOA Expressway is that most of the extension functions we have written to make configuration easier for BPEL based workflow are also available to the XSLT developer.
For those not familiar with SOA Expressway extension functions, they are granular operations that can be performed on the contents of messages or XML / JSON documents which SOA Expressway can embed into XPath or XSLT. What they add up to is a Swiss Army Knife for doing all sorts of useful things, especially when SOA Expressway is used in some message mediation or security mediation capacity.
The range of functions encompasses:
  • digest generation (MD5, SHA, etc.)
  • exslt functions for dates and regular expressions.
  • crypto and canonicalization.
  • full digital signature generation and verification.
  • encoding and decoding to binary, base64 etc.
  • timestamping, UUID generation, random numbers.
  • cookie and authentication token handling.
  • MIME attachment get and set.
Okay I could go on; there were more than two hundred functions the last time I counted. Go to our site at www.dynamicperimeter.com and request the full documentation set to find out more.
So how does an extension function get used in everyday life?
Here's how to write a message to the transaction log from within your XSLT. I'm assuming you have constructed a basic workflow and already have an XSL Transform action within it.
The basic form would look like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:soae-xf="http://www.intel.com/soae/xpath/">
<xsl:variable name="log" select="soae-xf:write-transaction-log('info',concat('Transaction ID:  ',soae-xf:get-transaction-id(),'; Comment: ','test',';'))"/>
<xsl:template match="/">
<!-- The variable is parsed lazily and is only evaluated when it is used in the test below. -->
<xsl:if test="$log"></xsl:if/>
<xsl:apply-templates /&g;
</xsl:template>
</xsl:stylesheet>



 There are three parts to remember:
1, Make sure your transform has the soae-xf, exslt or soae-cache namespace declared as appropriate (shown in blue).
2, Declare your Extension Function with a variable. In this case $log (shown in green).
3, Do something with the variable to force the evaluation of the variable. In this case we test $log for some contents. This is a necessary step since one of the performance features of the XSLT engine is lazy parsing which eliminates the evaluation of variables which may turn out to be unnecessary.
Interoperation between the workflow variables and execution steps and the nitty gritty of XSLT is necessary because it gives the developer added flexibility when it comes to mediating messaging in a product that's used as a gateway or ESB.

No hay comentarios:

Publicar un comentario