Я хочу преобразовать данные JSON в xml.По этой причине я использую функцию json-to-xml.
JSON
{
"example": {
"items": [
{
"_links": {
"self": {
"href": "xxx"
}
},
"test": "123",
"nummer": "456",
"parent": null,
"category": [
"test"
],
"select": true,
"values": {
"abc": [
{
"test": null,
"data": 2
}
]
},
"cpu": {
"1": {
"cpus": []
},
"3": {
"cpus": []
},
"4": {
"cpus": [
"cpu1"]
},
"5": {
"cpus": [
"cpu6"
]
}
}
},
{
"_links": {
"self": {
"href": "xxx"
}
},
"test": "789",
"nummer": "4110",
"parent": null,
"category": [
"test"
],
"select": true,
"values": {
"abc": [
{
"test": null,
"data": 2
}
]
},
"cpu": {
"1": {
"cpus": []
},
"3": {
"cpus": []
},
"4": {
"cpus": [
"cpu3"
]
},
"5": {
"cpus": [
"cpu4",
"cpu5"
]
}
}
}
]
}
}
xslt, который я использую:
<xsl:param name="input" select="'url json'"/>
<xsl:template name="initial">
<xsl:apply-templates select="json-to-xml(unparsed-text($input))" mode="copy"/>
</xsl:template>
<xsl:template match="node() | @*" mode="copy">
<xsl:copy>
<xsl:apply-templates select="node() | @*" mode="copy"/>
</xsl:copy>
</xsl:template>
У результата есть такой струкур:
<map xmlns="http://www.w3.org/2005/xpath-functions">
<map key="example">
<array key="items">
<map>
<map key="_links">
<map key="self">
<string key="href">xxx</string>
</map>
</map>
<string key="test">123</string>
<string key="nummer">456</string>
<null key="parent"/>
<array key="category">
<string>test</string>
</array>
<boolean key="select">true</boolean>
<map key="values">
<array key="abc">
<map>
<null key="test"/>
<number key="data">2</number>
</map>
</array>
</map>
<map key="cpu">
<map key="1">
<array key="cpus"/>
</map>
<map key="3">
<array key="cpus"/>
</map>
<map key="4">
<array key="cpus">
<string>cpu1</string>
</array>
</map>
<map key="5">
<array key="cpus">
<string>cpu6</string>
</array>
</map>
</map>
</map>
<map>
<map key="_links">
<map key="self">
<string key="href">xxx</string>
</map>
</map>
<string key="test">789</string>
<string key="nummer">4110</string>
<null key="parent"/>
<array key="category">
<string>test</string>
</array>
<boolean key="select">true</boolean>
<map key="values">
<array key="abc">
<map>
<null key="test"/>
<number key="data">2</number>
</map>
</array>
</map>
<map key="cpu">
<map key="1">
<array key="cpus"/>
</map>
<map key="3">
<array key="cpus"/>
</map>
<map key="4">
<array key="cpus">
<string>cpu3</string>
</array>
</map>
<map key="5">
<array key="cpus">
<string>cpu4</string>
<string>cpu5</string>
</array>
</map>
</map>
</map>
</array>
</map>
</map>
и это то, что яхочу.
<?xml version="1.0" encoding="UTF-8"?>
<example>
<items>
<_links>
<self>
<href>xxx</href>
</self>
</_links>
<test>123</test>
<nummer>456</nummer>
<parent>null</parent>
<category>test</category>
<select>true</select>
<values>
<abc>
<test>null</test>
<data>2</data>
</abc>
</values>
<cpu>
<_1></_1>
<_3></_3>
<_4>
<cpus>cpu1</cpus>
</_4>
<_5>
<cpus>cpu6</cpus>
</_5>
</cpu>
</items>
<items>
<_links>
<self>
<href>xxx</href>
</self>
</_links>
<test>789</test>
<nummer>4110</nummer>
<parent>null</parent>
<category>test</category>
<select>true</select>
<values>
<abc>
<test>null</test>
<data>2</data>
</abc>
</values>
<cpu>
<_1></_1>
<_3></_3>
<_4>
<cpus>cpu3</cpus>
</_4>
<_5>
<cpus>cpu4</cpus>
<cpus>cpu5</cpus>
</_5>
</cpu>
</items>
</example>
Я хочу удалить ключевые атрибуты.Дополнительно элемент "items" должен быть частью структуры xml.У кого-нибудь есть решение этой проблемы?
Заранее спасибо!