我必须显示一个层次结构,我的输入来自 XML 中的 Web 服务,如下所示:
<Nodes>
<Node>
<Data>
<Attribute name="ID">Desktop</Attribute>
<Attribute name="Parent">administrator</Attribute>
</Data>
<Relationship>
<RelatedNodes>
<Node>
<Data>
<Attribute name="ID">administrator</Attribute>>
<Attribute name="Parent">Users</Attribute>
</Data>
<Relationship>
<RelatedNodes>
<Node>
<Data>
<Attribute name="ID">Users</Attribute>
<Attribute name="Parent">C</Attribute>
</Data>
<Relationship>
<RelatedNodes>
<Node>
<Data>
<Attribute name="ID">C</Attribute>
<Attribute name="Parent"/>
</Data>
</Node>
</RelatedNodes>
</Relationship>
</Node>
</RelatedNodes>
</Relationship>
</Node>
</RelatedNodes>
</Relationship>
</Node>
</Nodes>
为了显示它,UI 人员要求我转换为这样的 JSON:
{
children:[{
"title": "C",
"level": "1",
"children": [
{
"title": "Users",
"level": "2",
"children": [
{
"title": "administrator",
"level": "3",
},
"children": [
{
"title": "Desktop",
"level": "4",
},
]
]
}
]
}]
}
关于如何使用 XSLT 或任何其他转换工具执行此操作的任何想法?
谢谢!