Reputation: 61
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
Upvotes: 1
Views: 305
Reputation: 14594
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>
Upvotes: 2