输入如下:
{
"customerDetail": {
"productId": 3455533,
"customerName": "TEST REDFOL",
"vendorCustId": "66209776",
"accountId": "6609776",
"myCustomerId": "7777376790",
"customerStatus": "SCHEDULED TO REMOVE",
"ctryCode": "CA",
"parentService": 4,
"remId": 140
"displayProduct": "ADT"
"carrierNameLabel": "Carrier Name"
}
}
我需要的输出如下所示,其中我可以放置自定义标签
{
"Name": "TEST REDFOL", "Customer Account No": "7777376790"
}
我需要XSL的帮助,需要遍历JSON数据的帮助。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all">
<xsl:output method="json" indent="yes"/>
<xsl:template match="*">
<xsl:sequence select="map{?*?customerName }"/>
</xsl:template>
</xsl:stylesheet>
这看起来相当直接:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:output method="json" indent="yes"/>
<xsl:template match="." name="xsl:initial-template">
<xsl:sequence
select="map {
'Name' : ?customerDetail?customerName,
'Customer Account No' : ?customerDetail?myCustomerId
}"/>
</xsl:template>
</xsl:stylesheet>
在线样本在这里。
XDM映射是无序的,所以你不能规定名称的顺序。