增强 XSL 以从平面树问题创建嵌套列表
我问了一个非常类似的问题([1]: XSL 创建扁平树问题的嵌套列表“从扁平树问题创建嵌套列表”)不久前,但我的问题略有扩大。最初我没有考虑列表中嵌套的段落。所以现在,输入:
<root>
<h1>text</h1>
<list level="1">num1</list>
<list level="1">num2</list>
<para type="indent">indented para1</para>
<list level="2">sub-num1</list>
<para type="indent">sub-indented para1</para>
<para type="indent">sub-indented para2</para>
<list level="2">sub-num2</list>
<list level="3">sub-sub-num1</list>
<list level="1">num3</list>
<p>text</p>
<list>num1</list>
<list>num2</list>
<h2>text</h2>
</root>
我需要这个输出:
<root>
<h1>text</h1>
<ol>
<li>num1</li>
<li>num2
<paragraph>indented para1</paragraph>
<ol>
<li>sub-num1
<paragraph>sub-indented para1</paragraph>
<paragraph>sub-indented para2</paragraph>
</li>
<li>sub-num2
<ol>
<li>sub-sub-num1</li>
</ol>
</li>
</ol>
</li>
<li>num3</li>
</ol>
<p>text</p>
<ol>
<li>num1</li>
<li>num2</li>
</ol>
<h2>text</h2>
</root>
也可能有缩进段落的实例不在列表中,但我想一旦我把这只猴子从我的背上拿下来我就可以弄清楚。 我需要使用 XSLT 1.0,再次感谢您的帮助。
I asked a very similar question ([1]: XSL to create nested list from flat tree problem "Create nested list from flat tree problem") a while ago, but my problem has expanded slightly. Originally I did not take into account paragraphs nested within lists. So now, with an input of:
<root>
<h1>text</h1>
<list level="1">num1</list>
<list level="1">num2</list>
<para type="indent">indented para1</para>
<list level="2">sub-num1</list>
<para type="indent">sub-indented para1</para>
<para type="indent">sub-indented para2</para>
<list level="2">sub-num2</list>
<list level="3">sub-sub-num1</list>
<list level="1">num3</list>
<p>text</p>
<list>num1</list>
<list>num2</list>
<h2>text</h2>
</root>
I need this output:
<root>
<h1>text</h1>
<ol>
<li>num1</li>
<li>num2
<paragraph>indented para1</paragraph>
<ol>
<li>sub-num1
<paragraph>sub-indented para1</paragraph>
<paragraph>sub-indented para2</paragraph>
</li>
<li>sub-num2
<ol>
<li>sub-sub-num1</li>
</ol>
</li>
</ol>
</li>
<li>num3</li>
</ol>
<p>text</p>
<ol>
<li>num1</li>
<li>num2</li>
</ol>
<h2>text</h2>
</root>
There may also be instances of indented paragraph that are not within a list, but I think I can figure that out once I've got this monkey off my back.
I need to use XSLT 1.0, and once again, any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无需对我之前的答案进行太多修改,此样式表:
输出:
注意:从概念上讲,这应该以
list
开头且最小@level
递归分组>。我将重构它以使其在语义上更加准确。编辑:语义上更接近的 XSLT 2.0 解决方案。
Without too much modifications to my previus answer, this stylesheet:
Output:
Note: Conceptually this should be recursively grouping starting with
list
with minimum@level
. I will refactor this to make it more semantically accurate.EDIT: More semantically closer XSLT 2.0 solution.