iegorov
2/19/2014 - 8:12 AM

xml to json

xml to json

<!--xml data
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="http://ws/credmon/vngrv/akbarsweb/xsl/createExecList.xsl"?>
<es:scenario_result xmlns:es="http://www.satc.ru/execution_scenario">
    <o:result xmlns:o="http://www.satc.ru/call_operation">
        <respondents_list>
            <respondent>
                <client_id>205215834000001</client_id>
                <cause_respondents_id>263886539000001</cause_respondents_id>
                <client_name>Ивановa Софья Семеновна</client_name>
                <is_juridical>0</is_juridical>
                <filial_distr>Филиал в г. Енисейск</filial_distr>
                <resp_contract_list>
                    <contract>
                        <clientcredit_id>205215842000001</clientcredit_id>
                        <contractnum>ГЕН-2036</contractnum>
                        <start_date>24.03.2009</start_date>
                        <finish_date>17.01.2010</finish_date>
                    </contract>
                    <contract>
                        <clientcredit_id>205215903000001</clientcredit_id>
                        <contractnum>ГЕН-2036</contractnum>
                        <start_date>01.07.2008</start_date>
                        <finish_date>01.06.2009</finish_date>
                    </contract>
                </resp_contract_list>
            </respondent>
            <respondent>
                <client_id>204415327000001</client_id>
                <cause_respondents_id>263885942000001</cause_respondents_id>
                <client_name>Кайгородов Даниил Тарасович</client_name>
                <is_juridical>0</is_juridical>
                <filial_distr>filial1</filial_distr>
                <resp_contract_list>
                    <contract>
                        <clientcredit_id>204415336000001</clientcredit_id>
                        <contractnum>ГЕН-10011</contractnum>
                        <start_date>17.07.2009</start_date>
                        <finish_date>19.05.2011</finish_date>
                    </contract>
                </resp_contract_list>
            </respondent>
        </respondents_list>
    </o:result>
    <es:common>
        <scenario_params scenario_name="scenario" operation="law.respondents.get">
            <cause_id>207894984000001</cause_id>
        </scenario_params>
    </es:common>
</es:scenario_result>
-->
<!--json data
{"205215834000001": {"client_name": "Ивановa Софья Семеновна","contracts": [{"clientcredit_id": "205215842000001","contractnum": "ГЕН-2036","start_date": "24.03.2009","finish_date": "17.01.2010"},{"clientcredit_id": "205215903000001","contractnum": "ГЕН-2036","start_date": "01.07.2008","finish_date": "01.06.2009"}]},"204415327000001": {"client_name": "Кайгородов Даниил Тарасович","contracts": [{"clientcredit_id": "204415336000001","contractnum": "ГЕН-10011","start_date": "17.07.2009","finish_date": "19.05.2011"}]}}
-->
<xsl:template match="/es:scenario_result/o:result/respondents_list">
		<xsl:text>'{</xsl:text>
		<xsl:for-each select="/es:scenario_result/o:result/respondents_list/respondent">
			<xsl:text>"</xsl:text><xsl:value-of select="client_id"/><xsl:text>": {</xsl:text>
			<xsl:text>"client_name": "</xsl:text><xsl:value-of select="client_name"/><xsl:text>",</xsl:text>
				<xsl:text>"contracts": [</xsl:text>
				<xsl:for-each select="resp_contract_list/contract">
					<xsl:text>{</xsl:text>
					<xsl:text>"clientcredit_id": "</xsl:text><xsl:value-of select="clientcredit_id"/><xsl:text>",</xsl:text>
					<xsl:text>"contractnum": "</xsl:text><xsl:value-of select="contractnum"/><xsl:text>",</xsl:text>
					<xsl:text>"start_date": "</xsl:text><xsl:value-of select="start_date"/><xsl:text>",</xsl:text>
					<xsl:text>"finish_date": "</xsl:text><xsl:value-of select="finish_date"/><xsl:text>"</xsl:text>
					<xsl:text>}</xsl:text><xsl:if test="./following-sibling::contract">,</xsl:if>
				</xsl:for-each>
				<xsl:text>]</xsl:text>
			<xsl:text>}</xsl:text><xsl:if test="./following-sibling::respondent">,</xsl:if>
		</xsl:for-each>
		<xsl:text>}'</xsl:text>
	</xsl:template>