使用 XSL 将 XML 列表转换为 XHTML 树
我需要获取这个 xml…
<root>
<item id=’1’ parent_id=’0’>ONE</item>
<item id=’2’ parent_id=’1’>TWO</item>
<item id=’3’ parent_id=’1’>THREE</item>
<item id=’4’ parent_id=’2’>FOUR</item>
<item id=’5’ parent_id=’0’>FIVE</item>
</root>
并生成这个 xhtml…
<div class=’parent’>ONE</div>
<div class=’child’>
<div class=’parent’>TWO</div>
<div class=’child’>
<div class=’parent’>FOUR</div>
</div>
<div class=’parent’>THREE</div>
</div>
<div class=’parent’>FIVE</div>
我知道如何收集子节点并将它们放在父节点下,但是如果我已经将它们用作子节点,我无法掌握如何跳过将它们视为父节点。
I need to take this xml…
<root>
<item id=’1’ parent_id=’0’>ONE</item>
<item id=’2’ parent_id=’1’>TWO</item>
<item id=’3’ parent_id=’1’>THREE</item>
<item id=’4’ parent_id=’2’>FOUR</item>
<item id=’5’ parent_id=’0’>FIVE</item>
</root>
And produce this xhtml…
<div class=’parent’>ONE</div>
<div class=’child’>
<div class=’parent’>TWO</div>
<div class=’child’>
<div class=’parent’>FOUR</div>
</div>
<div class=’parent’>THREE</div>
</div>
<div class=’parent’>FIVE</div>
I get how to collect the child nodes and put them under their parent, but I can’t grasp how to then skip over considering them as parents if I have already used them as children.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
测试了以下内容,这似乎有效
应用 root_id = 0 的根目录中的所有项目,然后递归地迭代任何子项。
Tested the following, which appears to work
Apply all items at the root with parent_id = 0, then recursively iterate for any children..
此样式表:
输出:
注意:交叉引用的键。
This stylesheet:
Output:
Note: Keys for cross references.