How to Automatically Generate a File Name for Received Files

Previous Next

See Also

This example generates customer specific filenames for files received  in the web service response. The example shows how to build a file path based upon information in the returned XML (1), how the user's home directory can be found from local properties (2) and how a formatted date can be retrieved (3). Using these items, a suitable file name can be made for the received file data.

The transformation is as follows:

<?xml version="1.0" encoding="windows-1252" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="" xmlns:ns1="MyMTOMProviderURN" xmlns:System="xalan://java.lang.System" xmlns:java="">

 <xsl:output method="xml" encoding="windows-1252" omit-xml-declaration="no" />

 <xsl:variable name="date" select="" />

 <xsl:variable name="sdf" select="'')" />

<xsl:template match="*|@*|comment()|processing-instruction()|text()">


 <xsl:apply-templates select="*|@*|text()|comment()|processing-instruction()" />



<xsl:template match="ns1:FileData">


<xsl:processing-instruction name="usoft-mtom">


 <xsl:value-of select="System:getProperty('user.home')" />


 <xsl:value-of select="local-name()" />

 <xsl:value-of select="java:format($sdf, $date)" />






The sections of this transformation associated with retrieving items for the file name are described below:

1. The sections of the transformation shown above that are concerned with building a file path based upon information in the returned XML are as follows (with comments):

<xsl:value-of select="local-name()"/>

The XML returned from the Web Service is used as part of the file name. Since we do not know the XML response format in this example we just ask for the name of the current node. In practical applications, the query might be something like select="concat(../ABCService/Filename,../ABCService/defaultExtension)"

2. The sections of the transformation concerned with extracting the user's home directory from the local properties are as follows:


Makes the java.lang.System.getproperty() method available for use below.

<xsl:value-of select="System:getProperty('user.home')"/>

The System name space is used to invoke a static method of the java.lang.System object.

3. The sections of the transformation that retrieve a formatted date are as follows:


Allows java objects to be created, as below.

<xsl:variable name="date" select=""/>

Creates a java Date object that holds the current date and time.

<xsl:variable name="sdf" select="'')"/>

Creates a simple date format to format the Date object into a string.

<xsl:value-of select="java:format($sdf, $date)"/>

The formatting of the current date by the simple date format is inserted as part of the desired file name.