对表格进行编号
输出应该是html,使用xsl输出目录,下面是xml
<book title="D">
<author>
<name>abc</name>
</author>
<chapter title="chapter1">
<section title="section1.1"/>
<section title="section1.2">
<section title="section1.2.1"/>
<section title="section1.2.2"/>
</section>
<section title="section1.3">
<section title="section1.3.1"/>
</section>
</chapter>
<chapter title="chapter2"/>
</book>
结果是 html,如下所示:
<body>
<h2>D</h2>
<p>
by abc
</p>
<h3>Table of contents</h3>
<ul>
<li>[1]chapter1
<ul>
<li>[1.1]section1.1</li>
<li>[1.2]section1.2
<ul>
<li>[1.2.1]section1.2.1</li>
<li>[1.2.2]section1.2.2</li>
</ul>
</li>
<li>[1.3]section1.3
<ul>
<li>[1.3.1]section1.3.1</li>
</ul>
</li>
</ul>
</li>
<li>[2]chapter2</li>
</ul>
</body>
The output should be html, use xsl to output the table of contents, following is the xml
<book title="D">
<author>
<name>abc</name>
</author>
<chapter title="chapter1">
<section title="section1.1"/>
<section title="section1.2">
<section title="section1.2.1"/>
<section title="section1.2.2"/>
</section>
<section title="section1.3">
<section title="section1.3.1"/>
</section>
</chapter>
<chapter title="chapter2"/>
</book>
the result is html, as this:
<body>
<h2>D</h2>
<p>
by abc
</p>
<h3>Table of contents</h3>
<ul>
<li>[1]chapter1
<ul>
<li>[1.1]section1.1</li>
<li>[1.2]section1.2
<ul>
<li>[1.2.1]section1.2.1</li>
<li>[1.2.2]section1.2.2</li>
</ul>
</li>
<li>[1.3]section1.3
<ul>
<li>[1.3.1]section1.3.1</li>
</ul>
</li>
</ul>
</li>
<li>[2]chapter2</li>
</ul>
</body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新:OP 在发布此解决方案后更改了他提供的 XML。下面的解决方案产生所需的正确编号。我更新它并不是为了赶上OP的更新,因为我不能把所有时间都花在等待下一次更新发生时。
使用
的强大之处在于,无论对标题的字符串值进行何种更新,生成的编号仍然是正确的。 :)此转换:
应用于提供的 XML 文档时:
产生所需的正确结果:
并由浏览器为:
d
由
abc
目录
说明:
使用
,其中level="multiple"
同时计算chapter
和section
。UPDATE: The OP changed his provided XML after this solution was posted. The solution below produces the wanted, correct numbering. I am not updating it in order to catch-up with the OP's update, because I cannot spend all my time waiting when every next update will happen.
The power of using
<xsl:number>
is that no matter what update is done to the string values of the titles, the produced numbering continues to be correct. :)This transformation:
when applied on the provided XML document:
produces the wanted, correct result:
and it is displayed by the browser as:
D
by
abc
Table of Contents
Explanation:
Use of
<xsl:number>
withlevel="multiple"
counting bothchapter
andsection
.此样式表:
在此输入上:
生成:
注意:调整了格式的空白。如果您实际上需要在请求的输出中提供的确切空格,那么您需要进行相应的修改。
This stylesheet:
On this input:
Produces:
Note: Whitespace adjusted for formatting. If you actually need the exact whitespace you provide in your requested output, then you'll need to modify accordingly.