Advanced Row Formatting - XSLT with Viper methods

Sxml formatting has a feature that allows you to call Sxml vipers from within an Xslt. This way you can use the rich viper functionality to perform operations on the Xml data you are transformating using Xslt.

In the attribute "select" of the element "xsl:value-of" you can see that the viper (or rather, the sxml viper expression) is a string parameter of the method "exec" in the namespace "viper". In this example the elements "Birth" and "Money" from the original xml are parameters for the method "exec". They will be converted to the correct type automatically by the Sxml parser. Because the viper expression is in a string parameter in an Xml attribute, you may easily run out of quotes. You can avoid this problem by using buffers to store temporary data. Note that the vipers are executed in the order defined by the way the Xslt parser works its way through your Xml.

Make sure that you have defined the viper namespace on the <xsl:stylesheet> element.

Smartsite iXperion 1.3

Since Smartsite iXperion 1.3, Viper methods can be called just like any other XSLT extension method.

XML Transform CopyCode image Copy Code
<xsl:value-of select="viper:exec('locale.formatlongdate(this.param(1)), ./Birth)" />

...can now be written as:

XML Transform CopyCode image Copy Code
<xsl:value-of select="viper:locale.formatlongdate(./Birth))" />

The new syntax has a number of advantages:

  • It makes the XSLT easier to read
  • It is more in line with general viper syntax
  • It allows viper methods to be combined with other methods, like native XSLT methods and extension methods in other namespaces.

Just remember to

  • prefix all calls to viper methods with 'viper:'
  • quote strings within parameters, because non-quoted strings are seen as XPath expressions.
  • not use named arguments when using viper methods in XSLT.