Dear Experts!!
As we all know that XML is the single solution for multiple problems
in the field of publishing. We can generate multiple formats from
single source and XSL is right choice to develop them. International
Digital Publishing Forum (formerly Open eBook Forum) has introduced a
new format i.e. ePub. In order to generate TOC, we have certain rules
which are shown in the required output. I have started to writing a
template with the help of my previous post but it seems that xslt is
letting me down in some areas like sequence generation, extracting
inner level sections etc. I am clueless as I am already very weak to
handling feature like key, collection, regex etc. Any help in this
direction is highly appreciable!!!
Rules
ABC (folder)
a.xml
b.xml
n.xml
1. Read the file folder ABC
2. Process each each XML one by one
A. Process a.xml
i. Extract article head
ii. Extract first level head
B. Process b.xml
i. Extract article head
ii. Extract first level head
N. Process nth.xml
i. Extract article head
ii. Extract first level head
3. Generate order sequence
XSL
<xsl:variable name="file-collection"
select="collection(concat(abc,'abc/?select=*.xml;recurse=yes'))" />
<xsl:template match="/">
<navMap>
<navLabel><text>Table of Contents</text></navLabel>
<xsl:for-each select="$file-collection">
<navPoint class="chapter" id="" playOrder="">
<navLabel><text><xsl:value-of
select="./doc//ti[@t='d']"/></text></navLabel>
<content>
<xsl:call-template name="source">
<xsl:with-param name="filename"><xsl:value-of
select="tokenize(document-uri(.), '/')[last()]"/></xsl:with-param>
</xsl:call-template>
</content>
<navPoint class="section1" id="" playOrder="">
<navLabel><text><xsl:value-of select="./doc//sc1"/></text></navLabel>
<content>
<xsl:call-template name="source">
<xsl:with-param name="filename"><xsl:value-of
select="tokenize(document-uri(.), '/')[last()]"/></xsl:with-param>
</xsl:call-template>
</content>
</navPoint>
</navPoint>
</xsl:for-each>
</navMap>
</xsl:template>
OUTPUT REQUIRED
<navMap>
<!-- ID and playOrder should be in sequence -->
<navPoint class="chapter" id="id1" playOrder="1">
<navLabel><text>Article head of A.xml</text></navLabel>
<content src="a.htm"/>
<navPoint class="section1" id="id2" playOrder="2">
<navLabel><text>Head 1: First level heading of A.xml (first
head)</text></navLabel>
<content src="a.htm#sec1"/>
</navPoint>
<navPoint class="section1" id="id3" playOrder="3">
<navLabel><text>Head 1: First level heading of A.xml (second
head)</text></navLabel>
<content src="a.htm#sec2"/>
</navPoint>
</navPoint>
<navPoint class="chapter" id="id4" playOrder="4">
<navLabel><text>Article head of B.xml</text></navLabel>
<content src="B.htm"/>
<navPoint class="section1" id="id5" playOrder="5">
<navLabel><text>Head 1: First level heading of B.xml (first
head)</text></navLabel>
<content src="b.htm#sec1"/>
</navPoint>
<navPoint class="section1" id="id6" playOrder="6">
<navLabel><text>Head 1: First level heading of A.xml (second
head)</text></navLabel>
<content src="b.htm#sec2"/>
</navPoint>
</navPoint>
...
</navMap>
Thanks in advance !!!
...JSR