I'm trying to fetch field inside json data
Input json
{
"data": {
"file": [{
"id": "0001",
"name": "harsha"
},
{
"id": "0002",
"name": "manohar"
}
]
}
}
XSLT style sheet
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0"
xmlns="http://www.w3.org/2005/xpath-functions" xpath-default-namespace="http://www.w3.org/2005/xpath-functions" expand-text="yes">
<xsl:param name="input"/>
<xsl:output method="text"/>
<xsl:template name="xsl:initial-template">
<xsl:variable name="input-as-xml" select="json-to-xml($input)"/>
<xsl:variable name="transformed-xml" as="element(map)">
<xsl:for-each select="$input-as-xml/map/array[@key='file']">
<map>
<string key="date">
<xsl:value-of select="../string[@key='name']"/>
</string>
</map>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="xml-to-json($transformed-xml)"/>
</xsl:template>
</xsl:stylesheet>
Here I'm trying to fetch name field but not able to fetch I'm getting empty data
{"date":""}
Any suggestions would be helpful...
json-to-xml($input)looks like. Then adjust your processing accordingly.<xsl:for-each select="$input-as-xml/map/array[@key='file']">but that doesn't select anything in your input. And which is the resulting XML and/or JSON you want to produce? You have twonamevalues so building a map with two properties of the same name is not going to work.