Hybrid Integration 10.2 | Integrating On-Premises Applications | Document Conventions | Building XSLT Services | Using Name/Value Pairs with an XSLT Service | Sample Style Sheet: Adding Name/Value Pairs to the Pipeline
 
Sample Style Sheet: Adding Name/Value Pairs to the Pipeline
The XSLT style sheet below uses the IOutputMap interface and extension functions from the Java classes Date and IntDate to add name/value pairs to the pipeline. IntDate is a simple class that converts a set of integers into a Date object.
<?xml version="1.0" ?>
<!--Declares namespaces for the XSL elements and Java functions-->
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:IOutput="com.wm.pkg.xslt.extension.IOutputMap"
xmlns:Date="java.util.Date"
xmlns:IntDate="com.wm.pkg.xslt.samples.date.IntDate"
exclude-result-prefixes="IOutput Date IntDate">
<!--Defines the XSLT parameters-->
<xsl:param name="output"/>
<xsl:param name="year"/>
<xsl:param name="month"/>
<xsl:param name="day"/>
<xsl:param name="hour"/>
<xsl:param name="minute"/>
<xsl:param name="second"/>
<xsl:param name="date" select=
"IntDate:getDate($year,$month,$day,$hour,$minute,$second)"/>
<xsl:output method="xml" indent="yes" />
 
<xsl:template match="/" >
<!--Converts the results of each parameter to a text string and adds
it to the $output variable-->
<xsl:value-of select="IOutput:put($output, 'year', $year)" />
<xsl:value-of select="IOutput:put($output, 'month', $month)" />
<xsl:value-of select="IOutput:put($output, 'day', $day)" />
<xsl:value-of select="IOutput:put($output, 'hour', $hour)" />
<xsl:value-of select="IOutput:put($output, 'minute', $minute)" />
<xsl:value-of select="IOutput:put($output, 'second', $second)" />
<xsl:value-of select="IOutput:put($output, 'date', $date)"/>
<xsl:apply-templates />
</xsl:template>
 
 
<!-- Adds a new element with a matching name for each text string
in the result tree.-->
<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
 
<xsl:template match="date" xml:space="preserve">
<!--For each variable, produces a text string consisting of a label
for the variable followed by the value of the variable-->
<xsl:text>year : </xsl:text><xsl:value-of select="$year"/>
<xsl:text>month : </xsl:text><xsl:value-of select="$month"/>
<xsl:text>day : </xsl:text><xsl:value-of select="$day"/>
<xsl:text>hour : </xsl:text><xsl:value-of select="$hour"/>
<xsl:text>minute : </xsl:text><xsl:value-of select="$minute"/>
<xsl:text>second : </xsl:text><xsl:value-of select="$second"/>
 
<!--Invokes a Date function and prints the resulting values-->
<xsl:text>converts to</xsl:text>
 
<xsl:value-of select="Date:toString($date)"/>
</xsl:template>
</xsl:stylesheet>
The following sample shows the IntDate class updated to use the compiling processor.
<?xml version="1.0" ?>
<!--Declares namespace for the XSL elements and Java functions-->
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsltc="http://xml.apache.org/xalan/xsltc"
xmlns:IOutput="com.wm.pkg.xslt.extension.IOutputMap"
xmlns:Date="java.util.Date"
xmlns:IntDate="com.wm.pkg.xslt.samples.date.IntDate"
exclude-result-prefixes="IOutput Date IntDate">
 
<!--Defines the XSLT parameters -->
<!--Explicitly casts $output-->
<xsl:param name="output" select=
"xsltc:cast('com.wm.pkg.xslt.extension.IOutputMap', $output)" />
<xsl:param name="year"/>
<xsl:param name="month"/>
<xsl:param name="day"/>
<xsl:param name="hour"/>
<xsl:param name="minute"/>
<xsl:param name="second"/>
<xsl:param name="date" select=
"IntDate:getDate($year,$month,$day,$hour,$minute,$second)"/>
<xsl:output method="xml" indent="yes" />
 
<xsl:template match="/" >
<!--Converts the results of each parameter to a text string and adds
it to the $output variable-->
<xsl:value-of select="IOutput:put($output, 'year', $year)" />
<xsl:value-of select="IOutput:put($output, 'month', $month)" />
<xsl:value-of select="IOutput:put($output, 'day', $day)" />
<xsl:value-of select="IOutput:put($output, 'hour', $hour)" />
<xsl:value-of select="IOutput:put($output, 'minute', $minute)" />
<xsl:value-of select="IOutput:put($output, 'second', $second)" />
<xsl:value-of select="IOutput:put($output, 'date', $date)" />
<xsl:apply-templates />
</xsl:template>
 
<!--Adds a new element with a matching name for each text string in
the result tree-->
<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
 
 
 <xsl:template match="date" xml:space="preserve">
  <!--Produces text string consisting of label for variable followed
by value of variable-->
  <xsl:text>year : </xsl:text><xsl:value-of select="$year"/>
<xsl:text>month : </xsl:text><xsl:value-of select="$month"/>
<xsl:text>day : </xsl:text><xsl:value-of select="$day"/>
<xsl:text>hour : </xsl:text><xsl:value-of select="$hour"/>
<xsl:text>minute : </xsl:text><xsl:value-of select="$minute"/>
<xsl:text>second : </xsl:text><xsl:value-of select="$second"/>
    
  <!--Invokes Date function and prints resulting values-->
<xsl:text>converts to</xsl:text>
<xsl:value-of select="Date:toString($date)"/>
</xsl:template>
</xsl:stylesheet>
When you run the service, provide the following input:
filename
packages/WmXSLT/pub/samples/xdocs/date.xml
xslParamInput
year
1997
month
05
day
21
hour
12
minute
12
second
12
The service uses the style sheet to transform the XML data from the source file specified in filename, converts the data into an XML string, and puts the string in the pipeline as the results parameter. The service also generates the name/value pairs and puts them in the xslParamOutput document. The Results view will display results similar to the following:

Copyright © 2015- 2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Innovation Release