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, see XPath and XQuery Functions and Operators Open link .

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:

  1. In   Development Studio, create a module and a process within that module for XSLT/XPath 2.0. 
  2. On the  Development Studio process canvas, using the Activity Palette, add a Call Adapter activity between the Start and End activity. 
  3. 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.

    Note

    The default name of the XSLT 2.0 adapter is SYSXSLTAdapter.

    The system adapter name must be unique. Do not enable any other adapter on the Grid with the same name.

    If you aren't connected to the CDP, the Use system adapters check box enables you to retrieve a list of system adapters available locally in the Development Studio. For a valid connection, you need not select the check box.

  4. For the Adapter Name, click Static Value and select the system adapter.
  5. For the Adapter Input, select Static Value and provide the adapter request. 

    Note

    In the adapter request, specify the transform that you want to use in the <xsl:template> element. Specify the input XML to be transformed in the <inputxml> element.

    The <inputxml> element is mandatory for running any request. For more information on how to create the request, see Request elements for the XSLT 2.0 system adapter.

    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>
  6. Select the Adapter Output to define the output as a context item. 

  7. From the Peer Location list, select Any to run the request on any peer on your environment.  
  8. Click OK to save the information.

  9. To test whether the workflow runs successfully, click Test Workflow.
  10. 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. 

    <html>
       <head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
          <title></title>
       </head>
       <body>
          <Name-Order-Pair>Name With Corresponding Order ID
             <Name>name1---------------------------QSEE343</Name>
             <Name>name2---------------------------ADAD6574</Name>
             <Name>name3---------------------------frgtttE3784</Name>
             <Name>name4---------------------------DFGG454</Name>
             <Name>name5---------------------------DFEUY34</Name>
          </Name-Order-Pair>
          <Name-Phone-Pair>Name With Phone Number
             <Name>name1---------------------------9555663451</Name>
             <Name>name2---------------------------953463451</Name>
             <Name>name3---------------------------9745673451</Name>
             <Name>name4---------------------------7734566341</Name>
             <Name>name5---------------------------2348765412</Name>
          </Name-Phone-Pair>
       </body>
    </html>

    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 elementDescriptionRequired
<system-adapter-request>Contains the complete adapter requestYes
<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. 

<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="/">
   <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. 

<system-adapter-response>
  <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. 

<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="/">
    <xsl:text>&#xA;Number formatting:&#xA;</xsl:text>
    <xsl:value-of select="format-number(0.23456, '#%')"  />
<xsl:text>&#xA; </xsl:text>
    <xsl:value-of select='format-number(500100, "#")'   />
<xsl:text>&#xA; </xsl:text>
<xsl:value-of select='format-number(500100, "0")'  />
<xsl:text>&#xA; </xsl:text>
<xsl:value-of select='format-number(500100, "#.00")'  />
<xsl:text>&#xA; </xsl:text>
<xsl:value-of select='format-number(500100, "#.0")'  />
<xsl:text>&#xA; </xsl:text>
<xsl:value-of select='format-number(500100, "###,###.00")'   />
<xsl:text>&#xA; </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. 

Number formatting:
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. 

<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="/">
    <xsl:text>&#xA;Tests of date and time formatting:&#xA;</xsl:text>
    <xsl:text>&#xA;  The current date is </xsl:text>
    <xsl:value-of select="format-date(current-date(), 
                          '[M01]/[D01]/[Y0001]')"/>
    <xsl:text>&#xA;  The current time is </xsl:text>
    <xsl:value-of select="format-time(current-time(), 
                          '[H01]:[m01] [z]')"/>
    <xsl:text>&#xA;  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. 

Tests of date and time formatting:

  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. 

<?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:output name="xml" method="xml" indent="yes"/>
<xsl:output name="html" method="html" indent="yes"/>
<xsl:output name="xhtml" method="xhtml" indent="yes"/>
<xsl:param name="dir">file:///C:\test1\</xsl:param>
<xsl:output method="text"/>
<xsl:template match="persons">
<xsl:apply-templates select="testvalue" mode="text"/>  
<xsl:result-document format="xml" href="{$dir}/persons.xml">
<persons>
<xsl:message terminate="no">Printing XML result tree</xsl:message>

<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>
<xsl:apply-templates select="testvalue" mode="xml"/>
</persons>
</xsl:result-document>
<xsl:result-document format="html" href="{$dir}/persons.html">
<xsl:message terminate="no">Printing HTML result tree </xsl:message>
<html>
<body>
<h2>Person List with User Id</h2>
<ul>
<xsl:for-each select="//person">
<li>
                                                                                      <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></li>
                                                                                      </xsl:for-each>
</ul>
</body>
</html>
</xsl:result-document>
<xsl:result-document format="xhtml" href="{$dir}/persons-x.html">
<xsl:message terminate="no">Printing XHTML result tree </xsl:message>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<h2>Person List with Phone Number</h2>
<ul>
<xsl:for-each select="//person">
<li>
                                                                                      <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>
</li>
                                                                                      </xsl:for-each>
</ul>
</body>
</html>
</xsl:result-document>
</xsl:template>
<xsl:template match="testvalue">
<xsl:value-of select="name"/>
<xsl:text> </xsl:text>
</xsl:template> 
<xsl:template match="testvalue" mode="xml">
<xsl:for-each select="//person">
                                                                                      <Name>
                                                                                      <xsl:value-of select="format-time(current-time(),'[H01]:[m01] [z]')" />
                                                                                                                   <xsl:value-of select="name" disable-output-escaping="no" />
                                                                                                     <xsl:value-of select="address/billing/orderId" disable-output-escaping="no" />
                                                                                      </Name>
                                                                                      </xsl:for-each>
</xsl:template>
<xsl:template match="testvalue" mode="html">
<xsl:for-each select="//person">
                                                                                      <Name>
                                                                                                                   <xsl:value-of select="name" disable-output-escaping="no" />
                                                                                                     <xsl:value-of select="address/billing/orderId" disable-output-escaping="no" />
                                                                                      </Name>
                                                                                      </xsl:for-each>
</xsl:template>
<xsl:template match="testvalue" mode="xhtml">
<li xmlns="http://www.w3.org/1999/xhtml">
<xsl:for-each select="//person">
                                                                                      <Name>
                                                                                      <xsl:value-of select="format-time(current-time(),'[H01]:[m01] [z]')" />
                                                                                                                   <xsl:value-of select="name" disable-output-escaping="no" />
                                                                                                     <xsl:value-of select="address/billing/orderId" disable-output-escaping="no" />
                                                                                      </Name>
                                                                                      </xsl:for-each></li>
</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>

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.

 

Related topics

Key concepts

Call Adapter activity

Troubleshooting XSLT 2.0 adapter

Was this page helpful? Yes No Submitting... Thank you

Comments