使用xstl展平XML
我有:使用xstl展平XML,xml,xslt,Xml,Xslt,我有: 节点1 材料1 节点11 填充物11 节点12 物品12 节点2 材料2 节点3 物品3 我希望最终得到一个平面结构,如: <nodes> <node> <name>node1</name> <other>stuff1</other> <node> <name>node11</name> <other>stuff1
节点1
材料1
节点11
填充物11
节点12
物品12
节点2
材料2
节点3
物品3
我希望最终得到一个平面结构,如:
<nodes>
<node>
<name>node1</name>
<other>stuff1</other>
<node>
<name>node11</name>
<other>stuff11</other>
</node>
<node>
<name>node12</name>
<other>stuff12</other>
</node>
</node>
<node>
<name>node2</name>
<other>stuff2</other>
</node>
<node>
<name>node3</name>
<other>stuff3</other>
</node>
</nodes>
节点1
材料1
节点11
填充物11
节点12
填充物21
节点2
材料2
节点3
物品3
这是一个简单的示例,但我希望复制每个节点中的所有元素,而不是嵌套的“节点”元素。我尝试复制来保留标签,但这也保留了嵌套。我也试过抄袭,但那把所有的孩子都排除在外了
有什么想法吗?我会使用XQuery。它是如此美好:
<nodes>
<node>
<name>node1</name>
<other>stuff1</other>
</node>
<node>
<name>node11</name>
<other>stuff11</other>
</node>
<node>
<name>node12</name>
<other>stuff21</other>
</node>
<node>
<name>node2</name>
<other>stuff2</other>
</node>
<node>
<name>node3</name>
<other>stuff3</other>
</node>
</nodes>
{//node/{(名称,其他)}
我会使用XQuery。它是如此美好:
<nodes>
<node>
<name>node1</name>
<other>stuff1</other>
</node>
<node>
<name>node11</name>
<other>stuff11</other>
</node>
<node>
<name>node12</name>
<other>stuff21</other>
</node>
<node>
<name>node2</name>
<other>stuff2</other>
</node>
<node>
<name>node3</name>
<other>stuff3</other>
</node>
</nodes>
{//node/{(名称,其他)}
这应该可以满足您的要求。对于顶级节点
元素,它按文档顺序为所有子节点
元素应用模板。对于每个节点
它复制所有非节点
子元素
<nodes>
{ //node/<node> { (name, other) } </node> }
</nodes>
这应该可以满足您的要求。对于顶级
节点
元素,它按文档顺序为所有子节点
元素应用模板。对于每个节点
它复制所有非节点
子元素
<nodes>
{ //node/<node> { (name, other) } </node> }
</nodes>