Hi,
I've made some modifications to directory2book.xsl (which generate side menu
based on directory content):
-little cleanup (expected-extension argument no more needed)
-kind of control on which items are present or not
-allow parametrable sorting of menu-items
-easily extensible.
Example: auto generate menu from several directories (named dir1,dir2, dir3)
full of document-v20 files. Each document file could have two meta tags
1- <meta name="short-title">short title</meta>
for the menu if title is too long
2- <meta name="date">20031002</meta>
used for sorting items by date
I use the xpathdirectory generator to extract the meta and title tags. I use
regexp matcher to factorize the matches.
-- sitemap.xmap snippet
<map:match pattern="(.*)(dir1|dir2|dir3)/book-(.*)" type="regexp">
<map:generate label="debug" src="content/xdocs/{1}{2}"
type="xpathdirectory">
<map:parameter name="depth" value="2"/>
<map:parameter name="xpath" value="/document/header/meta |
/document/header/title"/>
</map:generate>
<map:transform src="resources/stylesheets/documentdirectory2book.xsl">
<map:parameter name="sort-order" value="descending"/>
<map:parameter name="sort-select" value="dir:xpath/meta[@name='date']"/>
</map:transform>
<map:serialize type="xml"/>
</map:match>
---
i override the named template "get-label" in documentdirectory2book.xsl which
inherit from directory2book.xsl
--- documentdirectory2book.xsl snippet
<!-- label is short-title, title and in last resort filename -->
<xsl:template name="get-label">
<xsl:param name="corename"/>
<xsl:choose>
<xsl:when test="dir:xpath/meta[@name='short-title']">
<xsl:value-of select="dir:xpath/meta[@name='short-title']"/>
</xsl:when>
<xsl:when test="dir:xpath/title">
<xsl:value-of select="dir:xpath/title"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$corename"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
implementation:
1- substring-before-last is defined in a separate xsl file. With this named
template, expected-extension is no more needed
2- to able to change the select attribute of <xsl:sort/>, i use the dynamic
extension of exslt <dyn:evaluate>
(http://www.exslt.org/dyn/functions/evaluate/dyn.evaluate.html)
Hope it could help someone
|