The XSLT you’re using is a simple XML to JSON converter that does not manipulate the content or names of elements.
In your desired output, you want “name” to be the result of concatenating “first_name”, “middle_name” and “last_name”, and similarly you want “address” to be the concatenation of other elements.
I suggest you first run an XSL transformation that generates an XML with the desired elements (name and address) and then apply your XSL transformation, or better still use the XML to JSON policy which generates the same result, and it’s easier to understand and maintain.
After applying this XSL to your original XML:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml"/>
<xsl:template match="/">
<VisitorsN>
<xsl:for-each select="/child::*/child::*">
<xsl:variable name="curElementName" select="name()"/>
<xsl:element name="{$curElementName}">
<name>
<xsl:value-of select="normalize-space(concat(./first_name,' ', ./middle_name,' ', ./Last_name))"/>
</name>
<address>
<xsl:value-of select="normalize-space(concat(./house_number,', ',./road_namee,' ',./pincode))"/>
</address>
</xsl:element>
</xsl:for-each>
</VisitorsN>
</xsl:template>
</xsl:stylesheet>
you get this XML:
<?xml version="1.0" encoding="UTF-8"?>
<VisitorsN>
<VisitorA>
<name>Gov Kr Verma</name>
<address>15, ratu road 239809709</address>
</VisitorA>
<VisitorB>
<name>Amit Singh</name>
<address>, Harmu 398097692</address>
</VisitorB>
</VisitorsN>
You can then apply this XML2JSON policy (assuming the transformed XML is in the request):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XMLToJSON async="false" continueOnError="false" enabled="true" name="XML-to-JSON-1">
<DisplayName>XML to JSON-1</DisplayName>
<Properties/>
<Format>yahoo</Format>
<OutputVariable>jsonVar</OutputVariable>
<Source>request.content</Source>
</XMLToJSON>
to obtain the desired JSON output in a variable named jsonVar:
{
"VisitorsN": {
"VisitorA": {
"name": "Gov Kr Verma",
"address": "15, ratu road 239809709"
},
"VisitorB": {
"name": "Amit Singh",
"address": ", Harmu 398097692"
}
}
}