C# 如何使用xslt将嵌套Json对象转换为xml {“状态”:“C”,“响应代码”:200,“描述”:“成功”,“结果信息”:[{“sourceSystemAppID”:“825700008880”,“sourceSystemCustomerID”:“825
如何使用xslt将嵌套Json对象转换为xmlC# 如何使用xslt将嵌套Json对象转换为xml {“状态”:“C”,“响应代码”:200,“描述”:“成功”,“结果信息”:[{“sourceSystemAppID”:“825700008880”,“sourceSystemCustomerID”:“825,c#,asp.net,xml,xslt,javascriptserializer,C#,Asp.net,Xml,Xslt,Javascriptserializer,如何使用xslt将嵌套Json对象转换为xml {“状态”:“C”,“响应代码”:200,“描述”:“成功”,“结果信息”:[{“sourceSystemAppID”:“825700008880”,“sourceSystemCustomerID”:“8257000021453”,“sourceSystemName”:“FINCOR”,“customerType”:“AI”,“recordType”:“INPUT”,“name”:“TAMIZHARASI M”,“employerName”:“da
{“状态”:“C”,“响应代码”:200,“描述”:“成功”,“结果信息”:[{“sourceSystemAppID”:“825700008880”,“sourceSystemCustomerID”:“8257000021453”,“sourceSystemName”:“FINCOR”,“customerType”:“AI”,“recordType”:“INPUT”,“name”:“TAMIZHARASI M”,“employerName”:“dateOfBirth”:“08-10-1977”,“panNo”:“voterID”:“GSDF13891”,“护照号”:“驾驶执照”:“aadhaarNumber”:“gstNumber”:“registrationORCINNo”:“理性卡”:“nregaCard”:“Nationaldno”:“tanNo”:“性别”:“F”,“地址信息”:[{“地址类型”:“ressAddr”,“地址”:“49/2新克里希纳普拉姆Uyakondavari VIRUDHACHALAM”,“城市”:“VIRUDHACHALAM”,“州”:“TAMILNADU”,“pincode”:“607802”},{”地址类型“:”permAddr“,”地址“:”49/2新克里希纳普拉姆·乌亚康达瓦里·维鲁达恰拉姆“,”城市“,”维鲁达恰拉姆“,”州“,”泰米尔纳德邦“,”pincode“:”607802“,”,“{”地址类型“:”permAddr“,”地址“:”49/2新克里希纳普拉姆·乌亚康达瓦里·维鲁达恰拉姆“,”城市“,”维鲁达恰拉姆“,”州“,”泰米尔纳德邦“,”pincode“:”607802“,”电子邮件信息“,”电子邮件类型“:”RESEMAIL“,”emailID“:”}],”contactInformation“:”[{“电话类型”:“offPhone”,“phone”:“},{“电话类型”:“mobile”,“phone”:“9659306719”},{“电话类型”:“resphone”,“phone”:“}],”ckycNumber:“,”chassisNumber:“,”车辆注册号“,”备注“,”},{“sourceSystemAppID”:“0000”,“sourceSystemCustomerID”:“82570000021453”,“sourceSystemName”:”FINCOR、customerType:“AI”、“recordType:“ONLINE”、“name:“TAMIZHARASI M”、“employerName:“dateOfBirth:“08-10-1977”、“panNo:”voterID:“FEF2613891”、“passportNo:”drivingLicense:“Aadharnumber:”gstNumber:“registrationORCINNo:”理性卡:“nregaCard:”“Nationaldno:”、“tanNo:“性别:”F:“addressInformation:“{”地址类型“:”ressAddr“,”地址“:”49/2新克里希纳普拉姆·乌亚康达瓦里·维鲁达恰拉姆“,”城市“,”州“:”泰米尔纳德邦“,”pincode“:”607802“,”地址类型“:”offAddr“,”地址“:”49/2新克里希纳普拉姆·乌亚康达瓦里·维鲁达恰拉姆“,”城市“,”维鲁达恰拉姆“,”州“:”泰米尔纳德邦“,”pincode“:”607802“,”地址类型“,”offAddr“,”地址“:”49/2新KRISHNAPURAM Uyakondavari VIRUDHACHALAM,“城市”:“VIRUDHACHALAM”,“州”:“泰米尔纳都”,“pincode”:“607802”}],“电子邮件信息”:[{“电子邮件类型”:“其他人”,“电子邮件ID”:“}],“联系信息”:[{“电话类型”:“offPhone”,“phone”:“},{“phone类型”:“resphone”,“phone”:“},{“phone类型”:“mobile”,“phone”:“999999999”}],“ckycNumber”:“chassisNumber”:“,”engineNumber“:”车辆注册号“:”备注“:”},{”sourceSystemAppID“:”3181919“,”sourceSystemCustomerID“:”1“,”sourceSystemName“:”FINCOR“,”customerType“:”AI“,”recordType“:”ONLINE“,”姓名“:”TAMIZHARASI M“,”employerName“,”出生日期“:”1977年10月8日“,”panNo“,”voterID“,”GFG2613891“,”护照号“,”驾驶执照“,”AadharNumber“:”GSTNNumber:“registrationORCINNo:”理性卡“:”nregaCard:”Nationaldno:”tanNo:”性别:”F“,”地址信息“:[{”地址类型“:”ressAddr“,”地址“:”49/2新KRISHNAPURAM Uyakondavari VIRUDHACHALAM“,”城市“:”VIRUDHACHALAM“,”州“:”泰米尔纳都“,”pincode:”607802“,{”地址类型“:”offAddr“,”地址“:”49/2新克里希纳普拉姆·乌亚康达瓦里·维鲁达恰拉姆,“城市”:“维鲁达恰拉姆”,“州”:“泰米尔纳德邦”,“pincode”:“607802”},{“地址类型”:“offAddr”,“地址”:“49/2新克里希纳普拉姆·乌亚康达瓦里·维鲁达恰拉姆”,“城市”:“维鲁达恰拉姆”,“州”:“泰米尔纳德邦”,“pincode”:“607802”},““电子邮件信息”:[{“电子邮件类型”:“RESESEMAIL”,“电子邮件ID”:“}],“联系信息”:”“:[{”phoneType:“offPhone”,“phone:“},{”phoneType:“ResPhone”,“phone:“},{”phoneType:“mobile”,“phone:“9999999”}],“ckycNumber:“chassisNumber:”,“engineNumber:“VehiclerRegistrationNo:“,”备注:“},{”sourceSystemAppID:“31819”,“sourceSystemCustomerID:“358166”,“sourceSystemName:“FINCOR”,“customerType:”AI”,“recordType:“ONLINE”,“姓名”:“TAMIZHARASI M”,“雇员姓名”:“出生日期”:“1977年10月8日”,“帕诺”:“voterID”:“EYT2613891”,“护照号”:“驾驶执照”:“aadhaarNumber”:“gstNumber”:“registrationORCINNo”:“配给卡”:“nregaCard”:“Nationaldno”:“tanNo”:“性别”:“F”,“地址信息”:[{“地址类型”:“addressr”,“地址”:”49/2新克里希纳普拉姆·乌亚康达瓦里·维鲁达恰拉姆,“城市”:“维鲁达恰拉姆”,“州”:“泰米尔纳德邦”,“平码”:“607802”},{“地址类型”:“offAddr”,“地址”:“49/2新克里希纳普拉姆·乌亚康达瓦里·维鲁达恰拉姆”,“城市”:“维鲁达恰拉姆”,“州”:“泰米尔纳德邦”,“平码”:“607802”},{“地址类型”:“offAddr”,“地址”:49/2新KRISHNAPURAM Uyakondavari VIRUDHACHALAM,“城市”:“VIRUDHACHALAM”,“州”:“泰米尔纳德邦”,“pincode”:“607802”}],“电子邮件信息”:[{“电子邮件类型”:“Resemail”,“电子邮件ID”:“}],“联系信息”:[{“电话类型”:“offPhone”,“phone”:“},{“phone类型”:“resphone”,“phone”:“phone”:“mobile”,“phone”:“999999999”;“ckycNumber”:“chassisNumber”:”“,”engineNumber“:”车辆注册号“:”备注“:”},{”sourceSystemAppID“:”570000021422“,”sourceSystemCustomerID“:”82570000021422“,”sourceSystemName“:”BRNET“,”客户类型“:”AI“,”记录类型“:”在线“,”姓名“:”TAMIZHARASI M“,”员工姓名“,”出生日期“:”1977年8月10日“,”panNo“,”voterID“:”TYR2613891“,”护照号“,”驾驶执照“,”,“aadhaarNumber”:“gstNumber”:“registrationORCINNo”:“配给卡”:“nregaCard”:“nationaldno”:“tanNo”:“性别”:“F”,“addressInformation”:[{“addressType”:“others”,“address”:“pirni”,“city”:“verna”,“state”:“goa”,“pincode”:“403722”}],“emailInformation”:[{“emailType”:“others”,“emailID”:“shashank”。k@gmail.com}],“联系人信息”:[{”电话类型“:”手机“:”99999999“}],”ckycNumber“:”chassisNumber“:”引擎号码“:”车辆注册号“:”备注“:”},{”sourceSystemAppID“:”57000021453“,”sourceSystemCustomerID“:”8257000021452“,”sourceSystemName“:”BRMF“,”客户类型“:”AI“,”记录类型“:”在线“,”姓名“:”TAMIZHARASI M“,”员工姓名“,”出生日期“:”1977年8月10日“,”panNo“:”voterID“:”SGSG2613891“,”passportNo“,”驾驶执照“,”aadhaarNumber“,”gstNumber“,”registrationORCINNo“,”配给卡“,”nre“,”
<root><dataResponse>{"status":"C","responseCode":200,"description":"Success","resultsInformation":[{"sourceSystemAppID":"8257000008880","sourceSystemCustomerID":"82570000021453","sourceSystemName":"FINCOR","customerType":"AI","recordType":"INPUT","name":"TAMIZHARASI M ","employerName":"","dateOfBirth":"08-10-1977","panNo":"","voterID":"GSDF2613891","passportNo":"","drivingLicense":"","aadhaarNumber":"","gstNumber":"","registrationORCINNo":"","rationCard":"","nregaCard":"","nationalIdNo":"","tanNo":"","gender":"F","addressInformation":[{"addressType":"ressAddr","address":"49/2 NEW KRISHNAPURAM UYYAKONDAVARI VIRUDHACHALAM ","city":"VIRUDHACHALAM","state":"TAMILNADU","pincode":"607802"},{"addressType":"permAddr","address":"49/2 NEW KRISHNAPURAM UYYAKONDAVARI VIRUDHACHALAM ","city":"VIRUDHACHALAM","state":"TAMILNADU","pincode":"607802"},{"addressType":"permAddr","address":"49/2 NEW KRISHNAPURAM UYYAKONDAVARI VIRUDHACHALAM ","city":"VIRUDHACHALAM","state":"TAMILNADU","pincode":"607802"}],"emailInformation":[{"emailType":"ressEmail","emailID":""}],"contactInformation":[{"phoneType":"offPhone","phone":""},{"phoneType":"mobile","phone":"9659306719"},{"phoneType":"ressPhone","phone":""}],"ckycNumber":"","chassisNumber":"","engineNumber":"","vehicleRegistrationNo":"","remarks":""},{"sourceSystemAppID":"0000","sourceSystemCustomerID":"82570000021453","sourceSystemName":"FINCOR","customerType":"AI","recordType":"ONLINE","name":"TAMIZHARASI M ","employerName":"","dateOfBirth":"08-10-1977","panNo":"","voterID":"FEF2613891","passportNo":"","drivingLicense":"","aadhaarNumber":"","gstNumber":"","registrationORCINNo":"","rationCard":"","nregaCard":"","nationalIdNo":"","tanNo":"","gender":"F","addressInformation":[{"addressType":"ressAddr","address":"49/2 NEW KRISHNAPURAM UYYAKONDAVARI VIRUDHACHALAM ","city":"","state":"TAMILNADU","pincode":"607802"},{"addressType":"offAddr","address":"49/2 NEW KRISHNAPURAM UYYAKONDAVARI VIRUDHACHALAM ","city":"VIRUDHACHALAM","state":"TAMILNADU","pincode":"607802"},{"addressType":"offAddr","address":"49/2 NEW KRISHNAPURAM UYYAKONDAVARI VIRUDHACHALAM ","city":"VIRUDHACHALAM","state":"TAMILNADU","pincode":"607802"}],"emailInformation":[{"emailType":"others","emailID":""}],"contactInformation":[{"phoneType":"offPhone","phone":""},{"phoneType":"ressPhone","phone":""},{"phoneType":"mobile","phone":"999999999"}],"ckycNumber":"","chassisNumber":"","engineNumber":"","vehicleRegistrationNo":"","remarks":""},{"sourceSystemAppID":"3181919","sourceSystemCustomerID":"1","sourceSystemName":"FINCOR","customerType":"AI","recordType":"ONLINE","name":"TAMIZHARASI M ","employerName":"","dateOfBirth":"08-10-1977","panNo":"","voterID":"GFG2613891","passportNo":"","drivingLicense":"","aadhaarNumber":"","gstNumber":"","registrationORCINNo":"","rationCard":"","nregaCard":"","nationalIdNo":"","tanNo":"","gender":"F","addressInformation":[{"addressType":"ressAddr","address":"49/2 NEW KRISHNAPURAM UYYAKONDAVARI VIRUDHACHALAM ","city":"VIRUDHACHALAM","state":"TAMILNADU","pincode":"607802"},{"addressType":"offAddr","address":"49/2 NEW KRISHNAPURAM UYYAKONDAVARI VIRUDHACHALAM ","city":"VIRUDHACHALAM","state":"TAMILNADU","pincode":"607802"},{"addressType":"offAddr","address":"49/2 NEW KRISHNAPURAM UYYAKONDAVARI VIRUDHACHALAM ","city":"VIRUDHACHALAM","state":"TAMILNADU","pincode":"607802"}],"emailInformation":[{"emailType":"ressEmail","emailID":""}],"contactInformation":[{"phoneType":"offPhone","phone":""},{"phoneType":"ressPhone","phone":""},{"phoneType":"mobile","phone":"999999999"}],"ckycNumber":"","chassisNumber":"","engineNumber":"","vehicleRegistrationNo":"","remarks":""},{"sourceSystemAppID":"3181919","sourceSystemCustomerID":"358166","sourceSystemName":"FINCOR","customerType":"AI","recordType":"ONLINE","name":"TAMIZHARASI M ","employerName":"","dateOfBirth":"08-10-1977","panNo":"","voterID":"EYT2613891","passportNo":"","drivingLicense":"","aadhaarNumber":"","gstNumber":"","registrationORCINNo":"","rationCard":"","nregaCard":"","nationalIdNo":"","tanNo":"","gender":"F","addressInformation":[{"addressType":"ressAddr","address":"49/2 NEW KRISHNAPURAM UYYAKONDAVARI VIRUDHACHALAM ","city":"VIRUDHACHALAM","state":"TAMILNADU","pincode":"607802"},{"addressType":"offAddr","address":"49/2 NEW KRISHNAPURAM UYYAKONDAVARI VIRUDHACHALAM ","city":"VIRUDHACHALAM","state":"TAMILNADU","pincode":"607802"},{"addressType":"offAddr","address":"49/2 NEW KRISHNAPURAM UYYAKONDAVARI VIRUDHACHALAM ","city":"VIRUDHACHALAM","state":"TAMILNADU","pincode":"607802"}],"emailInformation":[{"emailType":"ressEmail","emailID":""}],"contactInformation":[{"phoneType":"offPhone","phone":""},{"phoneType":"ressPhone","phone":""},{"phoneType":"mobile","phone":"999999999"}],"ckycNumber":"","chassisNumber":"","engineNumber":"","vehicleRegistrationNo":"","remarks":""},{"sourceSystemAppID":"570000021422","sourceSystemCustomerID":"82570000021422","sourceSystemName":"BRNET","customerType":"AI","recordType":"ONLINE","name":"TAMIZHARASI M","employerName":"","dateOfBirth":"10-08-1977","panNo":"","voterID":"TYR2613891","passportNo":"","drivingLicense":"","aadhaarNumber":"","gstNumber":"","registrationORCINNo":"","rationCard":"","nregaCard":"","nationalIdNo":"","tanNo":"","gender":"F","addressInformation":[{"addressType":"others","address":"pirni","city":"verna","state":"goa","pincode":"403722"}],"emailInformation":[{"emailType":"others","emailID":"shashank.k@gmail.com"}],"contactInformation":[{"phoneType":"mobile","phone":"999999999"}],"ckycNumber":"","chassisNumber":"","engineNumber":"","vehicleRegistrationNo":"","remarks":""},{"sourceSystemAppID":"570000021453","sourceSystemCustomerID":"82570000021452","sourceSystemName":"BRMF","customerType":"AI","recordType":"ONLINE","name":"TAMIZHARASI M","employerName":"","dateOfBirth":"10-08-1977","panNo":"","voterID":"SGSG2613891","passportNo":"","drivingLicense":"","aadhaarNumber":"","gstNumber":"","registrationORCINNo":"","rationCard":"","nregaCard":"","nationalIdNo":"","tanNo":"","gender":"F","addressInformation":[{"addressType":"others","address":"pirni","city":"verna","state":"goa","pincode":"403722"}],"emailInformation":[{"emailType":"others","emailID":"DFSDFDSF.k@gmail.com"}],"contactInformation":[{"phoneType":"mobile","phone":"999999999"}],"ckycNumber":"","chassisNumber":"","engineNumber":"","vehicleRegistrationNo":"","remarks":""},{"sourceSystemAppID":"570000021453","sourceSystemCustomerID":"82570000021453","sourceSystemName":"BRMF","customerType":"AI","recordType":"ONLINE","name":"TAMIZHARASI M","employerName":"","dateOfBirth":"10-08-1977","panNo":"","voterID":"TYR2613891","passportNo":"","drivingLicense":"","aadhaarNumber":"","gstNumber":"","registrationORCINNo":"","rationCard":"","nregaCard":"","nationalIdNo":"","tanNo":"","gender":"F","addressInformation":[{"addressType":"others","address":"pirni","city":"verna","state":"goa","pincode":"403722"}],"emailInformation":[{"emailType":"others","emailID":"DSDSAD.k@gmail.com"}],"contactInformation":[{"phoneType":"mobile","phone":"9999999999"}],"ckycNumber":"","chassisNumber":"","engineNumber":"","vehicleRegistrationNo":"","remarks":""},{"sourceSystemAppID":"82570000021453","sourceSystemCustomerID":"82570000021453","sourceSystemName":"BRMF","customerType":"AI","recordType":"ONLINE","name":"TAMIZHARASI M","employerName":"","dateOfBirth":"10-08-1977","panNo":"","voterID":"Gtyv2613891","passportNo":"","drivingLicense":"","aadhaarNumber":"","gstNumber":"","registrationORCINNo":"","rationCard":"","nregaCard":"","nationalIdNo":"","tanNo":"","gender":"F","addressInformation":[{"addressType":"others","address":"pirni","city":"verna","state":"goa","pincode":"403722"}],"emailInformation":[{"emailType":"others","emailID":"shashank.k@gmail.com"}],"contactInformation":[{"phoneType":"mobile","phone":"9999999999"}],"ckycNumber":"","chassisNumber":"","engineNumber":"","vehicleRegistrationNo":"","remarks":""},{"sourceSystemAppID":"82570000021453","sourceSystemCustomerID":"82570000021856","sourceSystemName":"BRMF","customerType":"AI","recordType":"ONLINE","name":"TAMIZHARASI M","employerName":"","dateOfBirth":"10-08-1977","panNo":"","voterID":"YRV2613891","passportNo":"","drivingLicense":"","aadhaarNumber":"","gstNumber":"","registrationORCINNo":"","rationCard":"","nregaCard":"","nationalIdNo":"","tanNo":"","gender":"F","addressInformation":[],"emailInformation":[],"contactInformation":[{"phoneType":"mobile","phone":"999999999"}],"ckycNumber":"","chassisNumber":"","engineNumber":"","vehicleRegistrationNo":"","remarks":""},{"sourceSystemAppID":"8257000008881","sourceSystemCustomerID":"82570000021454","sourceSystemName":"FINCOR","customerType":"AI","recordType":"ONLINE","name":"TAMIZHARASI M ","employerName":"","dateOfBirth":"08-10-1977","panNo":"","voterID":"YRV2613891","passportNo":"","drivingLicense":"","aadhaarNumber":"","gstNumber":"","registrationORCINNo":"","rationCard":"","nregaCard":"","nationalIdNo":"","tanNo":"","gender":"F","addressInformation":[{"addressType":"ressAddr","address":"49/2 NEW KRISHNAPURAM UYYAKONDAVARI VIRUDHACHALAM ","city":"VIRUDHACHALAM","state":"TAMILNADU","pincode":"607802"},{"addressType":"offAddr","address":"49/2 NEW KRISHNAPURAM UYYAKONDAVARI VIRUDHACHALAM ","city":"VIRUDHACHALAM","state":"TAMILNADU","pincode":"607802"},{"addressType":"offAddr","address":"49/2 NEW KRISHNAPURAM UYYAKONDAVARI VIRUDHACHALAM ","city":"VIRUDHACHALAM","state":"TAMILNADU","pincode":"607802"}],"emailInformation":[{"emailType":"ressEmail","emailID":""}],"contactInformation":[{"phoneType":"offPhone","phone":""},{"phoneType":"ressPhone","phone":""},{"phoneType":"mobile","phone":"999999999"}],"ckycNumber":"","chassisNumber":"","engineNumber":"","vehicleRegistrationNo":"","remarks":""}]}</dataResponse><message>Request Completed Successfully</message><statusCode>000</statusCode><status>Success</status></root>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cs="urn:cs" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0" exclude-result-prefixes="msxsl cs">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<msxsl:script language="C#" implements-prefix="cs">
<msxsl:assembly name="System.Web.Extensions" />
<msxsl:using namespace="System.Collections.Generic" />
<msxsl:using namespace="System.Web.Script.Serialization" />
<![CDATA[public string getXMLFromJson(string jsonString){
string resp="";
var serializer = new JavaScriptSerializer();
Dictionary<string, object> result = (serializer.DeserializeObject(jsonString) as Dictionary<string, object>);
foreach(string key in result.Keys){
var newKey=key.Replace(" ","_");
resp+="<"+newKey+">"+result[key]+"</"+newKey+">";
}
return resp;
}]]>
</msxsl:script>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="root/dataResponse">
<xsl:variable name="jstr">
<xsl:value-of select="." />
</xsl:variable>
<dataResponse>
<xsl:value-of select="cs:getXMLFromJson($jstr)" disable-output-escaping="yes" />
</dataResponse>
</xsl:template>
</xsl:stylesheet>
<root>
<dataResponse><status>C</status><responseCode>200</responseCode><description>Success</description><resultsInformation>System.Object[]</resultsInformation></dataResponse>
<message>Request Completed Successfully</message>
<statusCode>000</statusCode>
<status>Success</status>
</root>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cs="urn:cs" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0" exclude-result-prefixes="msxsl cs">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:strip-space elements="*"/>
<msxsl:script language="C#" implements-prefix="cs">
<msxsl:assembly name="System.Xml.Linq" />
<msxsl:using namespace="Newtonsoft.Json" />
<msxsl:assembly name="Newtonsoft.Json" />
<msxsl:using namespace="System.Xml.Linq" />
<![CDATA[
public static XPathNavigator getXMLFromJson(string jsonString)
{
var xml = JsonConvert.DeserializeXmlNode(jsonString, "dataResponse");
return xml.CreateNavigator();
}
]]>
</msxsl:script>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="root/dataResponse">
<xsl:copy-of select="cs:getXMLFromJson(.)" />
</xsl:template>
</xsl:stylesheet>
<xsl:strip-space elements="*"/>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cs="urn:cs" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0" exclude-result-prefixes="msxsl cs">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:strip-space elements="*"/>
<msxsl:script language="C#" implements-prefix="cs">
<msxsl:assembly name="System.Core" />
<msxsl:assembly name="System.Xml.Linq" />
<msxsl:assembly name="System.Web.Extensions" />
<msxsl:using namespace="System.Collections.Generic" />
<msxsl:using namespace="System.Linq" />
<msxsl:using namespace="System.Xml.Linq" />
<msxsl:using namespace="System.Web.Script.Serialization" />
<![CDATA[
public static XPathNavigator XmlFromJson(string root, string json)
{
var jss = new JavaScriptSerializer();
var xml = ToXElement(root, (IDictionary<string, object>)jss.DeserializeObject(json));
return xml.CreateNavigator();
}
public static XElement ToXElement(string name, IDictionary<string, object> coll)
{
if (coll == null)
{
return new XElement(name, null);
}
return new XElement(
name,
coll.Select(x =>
x.Value is IDictionary<string, object> ? new[] { ToXElement(x.Key, (IDictionary<string, object>)x.Value) } :
x.Value is object[]? ToXElement(x.Key, (object[])x.Value) :
new[] { new XElement(x.Key, x.Value) }
).SelectMany(x => x)
.ToArray());
}
public static XElement[] ToXElement(string name, object[] coll)
{
if (coll == null)
{
return new[] { new XElement(name, null) };
}
return Array.ConvertAll(coll, x =>
x is IDictionary<string, object> ? ToXElement(name, (IDictionary<string, object>)x) :
x is object[]? new XElement(name, ToXElement(name, (object[])x)) :
new XElement(name, x)
);
}
]]>
</msxsl:script>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="root/dataResponse">
<xsl:copy-of select='cs:XmlFromJson("dataResponse", .)' />
</xsl:template>
</xsl:stylesheet>