Using XSLT/XPath 2.0
In earlier versions on
Platform, advanced transform editor only supports transforming XML documents by using the XSLT/XPath 1.0 functions. BMC has enabled support for XSLT/XPath 2.0 by introducing a system adapter, which enables you to manipulate data by using the XSLT/XPath 2.0 functions.
For a list of XSLT 2.0 functions, seeXPath and XQuery Functions and Operators.
When you install
Platform, the XSLT 2.0 adapter is installed and enabled on the Grid. However, this adapter cannot be configured manually on the Grid. XSLT 2.0 adapter is available in
Development Studio (for local test execution). Unlike
application or base adapters, system adapters are bundled with the
Platform and are pre-configured and enabled on the Grid.
Using XSLT 2.0 system adapter
XSLT 2.0 system adapter can be used via the Call-Adapter-activity. To use the XSLT 2.0 system adapter, perform the following steps:
- In
Development Studio, create a module and a process within that module for XSLT/XPath 2.0.
- On the
Development Studio process canvas, using the Activity Palette, add a Call-Adapter-activity between the Start and End activity.
In the properties panel of the Call Adapter activity, select the Use system adapters check box.
Currently, only the XSLT 2.0 adapter is displayed.- For the Adapter Name, click Static Value and select the system adapter.
For the Adapter Input, select Static Value and provide the adapter request.
The following figure shows a sample adapter request with for a For each function. In this example, a transform is specified for formatting the data in the <Name-Order-Pair> and <Name-Phone-Pair> format.
<?xml version="1.0" encoding="UTF-8"?>
<system-adapter-request><stylesheet><![CDATA[<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="persons">
<html>
<head>
<title>
</title>
</head>
<body>
<Name-Order-Pair>
<xsl:text disable-output-escaping="no">Name With Corresponding Order ID</xsl:text>
<xsl:for-each select="//person">
<Name>
<xsl:value-of select="name" disable-output-escaping="no" />
<xsl:text disable-output-escaping="no">---------------------------</xsl:text>
<xsl:value-of select="address/billing/orderId" disable-output-escaping="no" />
</Name>
</xsl:for-each>
</Name-Order-Pair>
<Name-Phone-Pair>
<xsl:text disable-output-escaping="no">Name With Phone Number</xsl:text>
<xsl:for-each select="//person">
<Name>
<xsl:value-of select="name" disable-output-escaping="no" />
<xsl:text disable-output-escaping="no">---------------------------</xsl:text>
<xsl:value-of select="address/billing/phone" disable-output-escaping="no" />
</Name>
</xsl:for-each>
</Name-Phone-Pair>
</body>
</html>
</xsl:template>
</xsl:stylesheet>]]>
</stylesheet><inputxml><![CDATA[
<searchPersonResponse>
<persons>
<person>
<name>name1</name>
<address>
<billing>
<orderId>QSEE343</orderId>
<phone>9555663451</phone>
<city>xx</city>
<state>yyyy</state>
<zip>zzzzz</zip>
</billing>
</address>
</person>
<person>
<name>name2</name>
<address>
<billing>
<orderId>ADAD6574</orderId>
<phone>953463451</phone>
<city>xx</city>
<state>yyyy</state>
<zip>zzzzz</zip>
</billing>
</address>
</person>
<person>
<name>name3</name>
<address>
<billing>
<orderId>frgtttE3784</orderId>
<phone>9745673451</phone>
<city>xx</city>
<state>yyyy</state>
<zip>zzzzz</zip>
</billing>
</address>
</person>
<person>
<name>name4</name>
<address>
<billing>
<orderId>DFGG454</orderId>
<phone>7734566341</phone>
<city>xx</city>
<state>yyyy</state>
<zip>zzzzz</zip>
</billing>
</address>
</person>
<person>
<name>name5</name>
<address>
<billing>
<orderId>DFEUY34</orderId>
<phone>2348765412</phone>
<city>xx</city>
<state>yyyy</state>
<zip>zzzzz</zip>
</billing>
</address>
</person>
</persons>
</searchPersonResponse>
]]>
</inputxml>
</system-adapter-request>- Select the Adapter Output to define the output as a context item.
- From the Peer Location list, select Any to run the request on any peer on your environment.
- Click OK to save the information.
- To test whether the workflow runs successfully, click Test Workflow.
In the Execution Mode dialog box, select Test as if triggered by a rule, schedule or SOAP. Then click OK.
Development Studio runs the process. The console window is opened below the design canvas, and the Process Log tab displays the results of the process execution. These are the same results that are posted to the processes.log file when the workflow is run on the grid.
The following figure shows the adapter output for the request. As specified in the request, data is grouped in a <Name-Order-Pair> and a <Name-Phone-Pair> format.
Request elements for XSLT 2.0 functions
The following table describes the elements to be used to create the XSLT 2.0 system adapter request.
Input element | Description | Required |
---|---|---|
<system-adapter-request> | Contains the complete adapter request | Yes |
<stylesheet> | Contains the transform to be applied to the data | Yes |
<inputxml> | Contains the input XML to be transformed You must always specify the <inputxml> element. | Yes |
Sample requests and responses for the XSLT 2.0 functions
This section describes the sample request and response for some of the XSLT 2.0 functions.
Simple transform
In this example, a simple transform is applied to format data by position, country, city list, and population.
<stylesheet><![CDATA[<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<table xsl:version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><tr><th>Position</th><th>Country</th><th>City List</th><th>Population</th></tr><xsl:for-each-group select="cities/city" group-by="@country"><tr><td><xsl:value-of select="position()"/></td><td><xsl:value-of select="@country"/></td><td><xsl:value-of select="current-group()/@name" separator=", "/></td><td><xsl:value-of select="sum(current-group()/@pop)"/></td></tr></xsl:for-each-group></table>
</xsl:template>
</xsl:stylesheet>]]>
</stylesheet>
<inputxml><![CDATA[
<cities><city name="Milano" country="Italia" pop="5"/><city name="Paris" country="France" pop="7"/><city name="Munchen" country="Deutschland" pop="4"/><city name="Lyon" country="France" pop="2"/><city name="Venezia" country="Italia" pop="1"/></cities>
]]>
</inputxml>
</system-adapter-request>
The following figure shows the output for the adapter request.
<table>
<tr>
<th>Position</th>
<th>Country</th>
<th>City List</th>
<th>Population</th>
</tr>
<tr>
<td>1</td>
<td>Italia</td>
<td>Milano, Venezia</td>
<td>6</td>
</tr>
<tr>
<td>2</td>
<td>France</td>
<td>Paris, Lyon</td>
<td>9</td>
</tr>
<tr>
<td>3</td>
<td>Deutschland</td>
<td>Munchen</td>
<td>4</td>
</tr>
</table>
</system-adapter-response>
Format numbers
In this example, numbers are formatted by using the XSLT 2.0 functions.
<stylesheet><![CDATA[<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:text>
Number formatting:
</xsl:text>
<xsl:value-of select="format-number(0.23456, '#%')" />
<xsl:text>
 </xsl:text>
<xsl:value-of select='format-number(500100, "#")' />
<xsl:text>
 </xsl:text>
<xsl:value-of select='format-number(500100, "0")' />
<xsl:text>
 </xsl:text>
<xsl:value-of select='format-number(500100, "#.00")' />
<xsl:text>
 </xsl:text>
<xsl:value-of select='format-number(500100, "#.0")' />
<xsl:text>
 </xsl:text>
<xsl:value-of select='format-number(500100, "###,###.00")' />
<xsl:text>
 </xsl:text>
</xsl:template>
</xsl:stylesheet>]]>
</stylesheet>
<inputxml><![CDATA[
<searchPersonResponse>
</searchPersonResponse>
]]>
</inputxml>
</system-adapter-request>
The following figure displays the output for the adapter request.
23%
500100
500100
500100.00
500100.0
500,100.00
Format data using current date and time
In this example, a transform is applied to format data by current date and time.
<stylesheet><![CDATA[<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:text>
Tests of date and time formatting:
</xsl:text>
<xsl:text>
 The current date is </xsl:text>
<xsl:value-of select="format-date(current-date(),
'[M01]/[D01]/[Y0001]')"/>
<xsl:text>
 The current time is </xsl:text>
<xsl:value-of select="format-time(current-time(),
'[H01]:[m01] [z]')"/>
<xsl:text>
 It's currently </xsl:text>
<xsl:value-of select="format-dateTime(current-dateTime(),
'[h1]:[m01] [P] on [MNn] [D].')"/>
</xsl:template>
</xsl:stylesheet>]]>
</stylesheet>
<inputxml><![CDATA[
<emptyInput>
</emptyInput>
]]>
</inputxml>
</system-adapter-request>
The following figure shows the adapter output for the request.
The current date is 11/06/2017
The current time is 18:33 GMT-12
It's currently 6:33 p.m. on November 6.
Multiple documents using xsl:result-document
XSLT 2.0 enables you to create multiple documents. In this example, transform is applied to create XML, HTML, and XHTML documents from the input XML.
For this function, output is not displayed in the Context Values tab.
The files are created at the specified location in a format specified in the transform.