Search code examples
xsltwso2xslt-1.0wso2-esb

Converting integer values to string in XSLT 1.0


I have an element in my XSLT named profileid. The value to this element can be expected as a set of numbers that is right now going as integer(eg. 452628), but this value has to be passed as a string to the next process. Is there a way I can convert this integer value to string within xslt itself? [I am using XSLT 1.0]

XSLT I've used:

<?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output indent="no" method="xml"/>
        <xsl:template match="/">
              <Session>
                <xsl:variable name="profileID" select="concat(' ',$profileid)"/>
                <profileId>
                    <xsl:value-of select="translate($profileID,' ','')"/>
                </profileId>
            </Session>
        </xsl:template>
    </xsl:stylesheet>

(Converted the xml response to json)

JSON output :-

{ "Session": { "profileId": 452628 } }

Expected JSON output:_

{ "Session": { "profileId": "452628" } }

A way to convert this integer value to String inside xslt


Solution

  • Assuming you want all the attributes as String values. After the XSLT transformation set the following property using JSON Transform Mediator

    <jsontransform>
        <property name="synapse.commons.json.output.autoPrimitive" value = "false"/>
    </jsontransform>