-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhtmltoc.xslt
20 lines (20 loc) · 850 Bytes
/
htmltoc.xslt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="kFollowing" match="body/*" use="generate-id(preceding-sibling::*[starts-with(name(),'h')][1])"/>
<xsl:template match="//body">
<ul>
<xsl:apply-templates select="//h1" />
</ul>
</xsl:template>
<xsl:template match="//h1">
<li><xsl:apply-templates select="node()" /></li>
<xsl:if test="count(following::h2[generate-id(preceding::h1[1])=generate-id(current())]) > 0">
<ul>
<xsl:apply-templates select="following::h2[generate-id(preceding::h1[1])=generate-id(current())]"/>
</ul>
</xsl:if>
</xsl:template>
<xsl:template match="//h2">
<li><xsl:apply-templates select="node()" /></li>
</xsl:template>
</xsl:stylesheet>