英文:
Converting integer values to string in XSLT 1.0
问题
You can convert the integer value to a string within XSLT by using the string()
function. Here's how you can modify your XSLT to achieve the expected JSON output:
<?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="string(profileid)"/>
<profileId>
<xsl:value-of select="$profileID"/>
</profileId>
</Session>
</xsl:template>
</xsl:stylesheet>
With this XSLT, the value of <profileID>
will be converted to a string, resulting in the expected JSON output:
{
"Session": {
"profileId": "452628"
}
}
英文:
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. <profileID>452628</profileID>), 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
答案1
得分: 2
在XSLT转换后,假设您希望将所有属性作为字符串值。使用JSON Transform Mediator设置以下属性:
<jsontransform>
<property name="synapse.commons.json.output.autoPrimitive" value="false"/>
</jsontransform>
英文:
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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论