I'm trying to reorder the output of the topics in the nav.xhtml (epub) based on the following condition:
if topic A (could be more than 1 topic A) precedes topic B in the ditamap, then place the <li>
of topic A after the <li>
of topic B so that the nav would now look like this
<li>topic xx</li>
<li>topic xx</li>
<li>topic xx</li>...
<li>topic B</li>
<li>topic A</li>
<li>topic A</li>
I have managed to suppress the first output (i.e., natural order) of <li>topic A</li>
. Then, I output the <li>topic B</li>
.
I create the <li>topic A</li>
(using xsl:for-each topicA) right after the <li>topic B</li>
. I'm doing a manual build, but it's not quite working. I've used preceding-sibling::*[@outputclass='topic A']/@id
to reinsert the id (or $linkId) value from topic A, but it's not working.
I did manage to insert the topic title for the preceding topic A by using:
<xsl:apply-templates select="preceding-sibling::*[@outputclass='topic A']" mode="nav-point-title"/>
but this only outputs the first title in the second li, so that it looks something like this:
<li class="tocrm" id=""><a href="XX"></a></li>
<li class="tocrm" id=""><a href="XX">Topic A1</a></li>
[NOTE that I haven't yet added the code to include the href yet. That's next on the list!]
It would be great if I could reuse the $linkId, etc. variables, but they don't seem to want to work in the context of topic B. I know I'm probably not going to get an answer to this question as it's so complicated, but I've tried hundreds of iterations and I'm at a loss. Any suggestions would be much appreciated. Sincerely, struggling d4p user
Perhaps you can just change the order of processing in e.g. https://github.com/dita4publishers/org.dita4publishers.epub/blob/develop/xsl/map2epubHtmlTocImpl.xsl#L40 by using
<xsl:variable name="b-topics" select="*[df:class(., 'map/topicref')][@title = 'topic B']"/>
<xsl:variable name="a-topics" select="$b-topics/preceding-sibling::*[df:class(., 'map/topicref')][@title = 'topic A']"/>
<xsl:variable name="others" select="$b-topics/preceding-sibling::*[df:class(., 'map/topicref')][@title != 'topic A']"/>
<xsl:apply-templates select="$others, $b-topics, $a-topics, $b-topics/following-sibling::*[df:class(., 'map/topicref')]" mode="#current">
instead of
<xsl:apply-templates select="*[df:class(., 'map/topicref')]" mode="#current">