docbook-apps

  • 1.  generating javascript navigation

    Posted 04-14-2008 14:40
    Hello,

    recently I looked at a JavaScript TOC navigation plugin for DITA which uses the Yahoo treeview library (http://developer.yahoo.com/yui/treeview/). I would like to use this library for docbook html output and generate javascript navigation tree.

    The navigation is contained in a javascript file and has following structure:

    var objd0 = { label: "Book ", href:"index.html", target:"content"};
    var d0 = new YAHOO.widget.TextNode(objd0, root, false);

    var objd0e5 = { label: "Preface ", href:"pr01.html", target:"content"};
    var d0e5 = new YAHOO.widget.TextNode(objd0e5, root, false);

    var objd0e10 = { label: "Chapter 1 ", href:"ch01.html", target:"content"};
    var d0e10 = new YAHOO.widget.TextNode(objd0e10, root, false);

    var objd0e13 = { label: "Section 1 ", href:"ch01.html#d0e13", target:"content"};
    var d0e13 = new YAHOO.widget.TextNode(objd0e13, root, false);

    So far I have been able to generate working javascript but was not able to get the right hierarchical structure of the tree. When generating for example the section node I need to get the ID of the parent element (chapter, other section ect.). Consider following example:

    Having Chapter 1 and Section 1 I need to get the recursion the right way. While component titles should have the "root" value

    var d0e13 = new YAHOO.widget.TextNode(objd0e13, root, false);

    sections etc. should get the ID of parent element instead.


    My stylesheet is based on Eclipse stylesheet:


    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ng="http://docbook.org/docbook-ng" xmlns:db="http://docbook.org/ns/docbook"
    xmlns:exsl="http://exslt.org/common" version="1.0" exclude-result-prefixes="exsl db ng">

    <xsl:import href="../html/chunk.xsl"/>

    <xsl:template match="/">
    <xsl:call-template name="jstoc"/>
    </xsl:template>

    <xsl:template match="text()" mode="jstoc"/>


    <xsl:template name="jstoc">
    <xsl:call-template name="write.chunk">
    <xsl:with-param name="filename">
    <xsl:if test="$manifest.in.base.dir != 0">
    <xsl:value-of select="$base.dir"/>
    </xsl:if>
    <xsl:value-of select="'toctree.js'"/>
    </xsl:with-param>
    <xsl:with-param name="method" select="'text'"/>
    <xsl:with-param name="encoding" select="'utf-8'"/>
    <xsl:with-param name="indent" select="'yes'"/>
    <xsl:with-param name="content">

    <xsl:text>
    var tree;

    function treeInit() {
    tree = new YAHOO.widget.TreeView("treeDiv1");
    var root = tree.getRoot();
    </xsl:text>

    <xsl:variable name="parent" select="'root'"/>

    <xsl:variable name="title">
    <xsl:apply-templates select="/*" mode="title.markup"/>
    </xsl:variable>
    <xsl:variable name="href">
    <xsl:call-template name="href.target.with.base.dir">
    <xsl:with-param name="object" select="/"/>
    </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="self" select="generate-id()"/>


    <xsl:text>var </xsl:text>
    <xsl:value-of select="concat('obj', $self)"/>
    <xsl:text> = { label: "</xsl:text>
    <xsl:value-of select="$title"/>
    <xsl:text> ", href:"</xsl:text>
    <xsl:value-of select="$href"/>
    <xsl:text>", target:"content"};</xsl:text>

    <xsl:text>var </xsl:text>
    <xsl:value-of select="$self"/>
    <xsl:text> = new YAHOO.widget.TextNode(</xsl:text>
    <xsl:value-of select="concat('obj', $self)"/>
    <xsl:text>, </xsl:text>
    <xsl:value-of select="'root'"/>
    <xsl:text>, false);</xsl:text>

    <xsl:apply-templates select="/*/*" mode="jstoc"/>


    <xsl:text>
    tree.draw();
    }

    YAHOO.util.Event.addListener(window, "load", treeInit);
    </xsl:text>

    </xsl:with-param>
    </xsl:call-template>

    </xsl:template>




    <xsl:template
    match="book|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index"
    mode="jstoc">

    <xsl:variable name="title">
    <xsl:apply-templates select="." mode="title.markup"/>
    </xsl:variable>

    <xsl:variable name="href">
    <xsl:call-template name="href.target.with.base.dir">
    <xsl:with-param name="context" select="/"/>
    </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="jsid" select="generate-id()"/>

    <xsl:text>var </xsl:text>
    <xsl:value-of select="concat('obj', $jsid)"/>
    <xsl:text> = { label: "</xsl:text>
    <xsl:value-of select="$title"/>
    <xsl:text> ", href:"</xsl:text>
    <xsl:value-of select="$href"/>
    <xsl:text>", target:"content"};</xsl:text>

    <xsl:text>var </xsl:text>
    <xsl:value-of select="$jsid"/>
    <xsl:text> = new YAHOO.widget.TextNode(</xsl:text>
    <xsl:value-of select="concat('obj', $jsid)"/>
    <xsl:text>, </xsl:text>


    <xsl:value-of select="'root'"/>
    <xsl:text>, false);</xsl:text>

    <xsl:apply-templates
    select="part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index"
    mode="jstoc"/>
    </xsl:template>

    <xsl:template match="text()" mode="jstoc"/>

    </xsl:stylesheet>


    Any ideas are very appreciated.

    Greetings,
    Pavel Škopík







  • 2.  RE: [docbook-apps] generating javascript navigation

    Posted 04-14-2008 16:51
    Skopik,



    I ran into that recently too... and found the cause and the solution in an earlier post by Bob Stayton on this newsgroup:



    The DocBook titlepage specs include a separator item after the title pages:



    <t:titlepage-separator>

    <fo:block break-after="page"/>

    </t:titlepage-separator>



    This is supposed to just force a page break after the end of the verso

    titlepage content. This works fine in XEP and Antenna House, but FOP

    creates an extra page with it. This is a long standing bug in FOP's

    handling of breaks... Making this an empty element would eliminate the extra

    blank page before the TOC:



    <t:titlepage-separator>

    </t:titlepage-separator>



    Hope that helps...



    Alan





    From: Skopik Pavel [mailto:Pavel.Skopik@aipsafe.cz]
    Sent: Monday, April 14, 2008 7:40 AM
    To: docbook-apps@lists.oasis-open.org
    Subject: [docbook-apps] generating javascript navigation



    Hello,



    recently I looked at a JavaScript TOC navigation plugin for DITA which uses the Yahoo treeview library (http://developer.yahoo.com/yui/treeview/). I would like to use this library for docbook html output and generate javascript navigation tree.



    The navigation is contained in a javascript file and has following structure:



    var objd0 = { label: "Book ", href:"index.html", target:"content"};

    var d0 = new YAHOO.widget.TextNode(objd0, root, false);



    var objd0e5 = { label: "Preface ", href:"pr01.html", target:"content"};

    var d0e5 = new YAHOO.widget.TextNode(objd0e5, root, false);



    var objd0e10 = { label: "Chapter 1 ", href:"ch01.html", target:"content"};

    var d0e10 = new YAHOO.widget.TextNode(objd0e10, root, false);



    var objd0e13 = { label: "Section 1 ", href:"ch01.html#d0e13", target:"content"};

    var d0e13 = new YAHOO.widget.TextNode(objd0e13, root, false);



    So far I have been able to generate working javascript but was not able to get the right hierarchical structure of the tree. When generating for example the section node I need to get the ID of the parent element (chapter, other section ect.). Consider following example:



    Having Chapter 1 and Section 1 I need to get the recursion the right way. While component titles should have the "root" value



    var d0e13 = new YAHOO.widget.TextNode(objd0e13, root, false);



    sections etc. should get the ID of parent element instead.





    My stylesheet is based on Eclipse stylesheet:





    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

    xmlns:ng="http://docbook.org/docbook-ng" xmlns:db="http://docbook.org/ns/docbook"

    xmlns:exsl="http://exslt.org/common" version="1.0" exclude-result-prefixes="exsl db ng">



    <xsl:import href="../html/chunk.xsl"/>



    <xsl:template match="/">

    <xsl:call-template name="jstoc"/>

    </xsl:template>



    <xsl:template match="text()" mode="jstoc"/>





    <xsl:template name="jstoc">

    <xsl:call-template name="write.chunk">

    <xsl:with-param name="filename">

    <xsl:if test="$manifest.in.base.dir != 0">

    <xsl:value-of select="$base.dir"/>

    </xsl:if>

    <xsl:value-of select="'toctree.js'"/>

    </xsl:with-param>

    <xsl:with-param name="method" select="'text'"/>

    <xsl:with-param name="encoding" select="'utf-8'"/>

    <xsl:with-param name="indent" select="'yes'"/>

    <xsl:with-param name="content">



    <xsl:text>

    var tree;



    function treeInit() {

    tree = new YAHOO.widget.TreeView("treeDiv1");

    var root = tree.getRoot();

    </xsl:text>



    <xsl:variable name="parent" select="'root'"/>



    <xsl:variable name="title">

    <xsl:apply-templates select="/*" mode="title.markup"/>

    </xsl:variable>

    <xsl:variable name="href">

    <xsl:call-template name="href.target.with.base.dir">

    <xsl:with-param name="object" select="/"/>

    </xsl:call-template>

    </xsl:variable>



    <xsl:variable name="self" select="generate-id()"/>





    <xsl:text>var </xsl:text>

    <xsl:value-of select="concat('obj', $self)"/>

    <xsl:text> = { label: "</xsl:text>

    <xsl:value-of select="$title"/>

    <xsl:text> ", href:"</xsl:text>

    <xsl:value-of select="$href"/>

    <xsl:text>", target:"content"};</xsl:text>



    <xsl:text>var </xsl:text>

    <xsl:value-of select="$self"/>

    <xsl:text> = new YAHOO.widget.TextNode(</xsl:text>

    <xsl:value-of select="concat('obj', $self)"/>

    <xsl:text>, </xsl:text>

    <xsl:value-of select="'root'"/>

    <xsl:text>, false);</xsl:text>



    <xsl:apply-templates select="/*/*" mode="jstoc"/>





    <xsl:text>

    tree.draw();

    }



    YAHOO.util.Event.addListener(window, "load", treeInit);

    </xsl:text>



    </xsl:with-param>

    </xsl:call-template>



    </xsl:template>









    <xsl:template

    match="book|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index"

    mode="jstoc">



    <xsl:variable name="title">

    <xsl:apply-templates select="." mode="title.markup"/>

    </xsl:variable>



    <xsl:variable name="href">

    <xsl:call-template name="href.target.with.base.dir">

    <xsl:with-param name="context" select="/"/>

    </xsl:call-template>

    </xsl:variable>



    <xsl:variable name="jsid" select="generate-id()"/>



    <xsl:text>var </xsl:text>

    <xsl:value-of select="concat('obj', $jsid)"/>

    <xsl:text> = { label: "</xsl:text>

    <xsl:value-of select="$title"/>

    <xsl:text> ", href:"</xsl:text>

    <xsl:value-of select="$href"/>

    <xsl:text>", target:"content"};</xsl:text>



    <xsl:text>var </xsl:text>

    <xsl:value-of select="$jsid"/>

    <xsl:text> = new YAHOO.widget.TextNode(</xsl:text>

    <xsl:value-of select="concat('obj', $jsid)"/>

    <xsl:text>, </xsl:text>





    <xsl:value-of select="'root'"/>

    <xsl:text>, false);</xsl:text>



    <xsl:apply-templates

    select="part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index"

    mode="jstoc"/>

    </xsl:template>



    <xsl:template match="text()" mode="jstoc"/>



    </xsl:stylesheet>





    Any ideas are very appreciated.



    Greetings,

    Pavel Škopík












  • 3.  RE: [docbook-apps] generating javascript navigation

    Posted 04-14-2008 17:07
    Sorry, this response was posted to the wrong question! Not quite sure how I managed that.. must be the Monday morning thing....



    Alan



    From: Alan Oehler
    Sent: Monday, April 14, 2008 9:51 AM
    To: Skopik Pavel; docbook-apps@lists.oasis-open.org
    Subject: RE: [docbook-apps] generating javascript navigation



    Skopik,



    I ran into that recently too... and found the cause and the solution in an earlier post by Bob Stayton on this newsgroup:



    The DocBook titlepage specs include a separator item after the title pages:



    <t:titlepage-separator>

    <fo:block break-after="page"/>

    </t:titlepage-separator>



    This is supposed to just force a page break after the end of the verso

    titlepage content. This works fine in XEP and Antenna House, but FOP

    creates an extra page with it. This is a long standing bug in FOP's

    handling of breaks... Making this an empty element would eliminate the extra

    blank page before the TOC:



    <t:titlepage-separator>

    </t:titlepage-separator>



    Hope that helps...



    Alan





    From: Skopik Pavel [mailto:Pavel.Skopik@aipsafe.cz]
    Sent: Monday, April 14, 2008 7:40 AM
    To: docbook-apps@lists.oasis-open.org
    Subject: [docbook-apps] generating javascript navigation



    Hello,



    recently I looked at a JavaScript TOC navigation plugin for DITA which uses the Yahoo treeview library (http://developer.yahoo.com/yui/treeview/). I would like to use this library for docbook html output and generate javascript navigation tree.



    The navigation is contained in a javascript file and has following structure:



    var objd0 = { label: "Book ", href:"index.html", target:"content"};

    var d0 = new YAHOO.widget.TextNode(objd0, root, false);



    var objd0e5 = { label: "Preface ", href:"pr01.html", target:"content"};

    var d0e5 = new YAHOO.widget.TextNode(objd0e5, root, false);



    var objd0e10 = { label: "Chapter 1 ", href:"ch01.html", target:"content"};

    var d0e10 = new YAHOO.widget.TextNode(objd0e10, root, false);



    var objd0e13 = { label: "Section 1 ", href:"ch01.html#d0e13", target:"content"};

    var d0e13 = new YAHOO.widget.TextNode(objd0e13, root, false);



    So far I have been able to generate working javascript but was not able to get the right hierarchical structure of the tree. When generating for example the section node I need to get the ID of the parent element (chapter, other section ect.). Consider following example:



    Having Chapter 1 and Section 1 I need to get the recursion the right way. While component titles should have the "root" value



    var d0e13 = new YAHOO.widget.TextNode(objd0e13, root, false);



    sections etc. should get the ID of parent element instead.





    My stylesheet is based on Eclipse stylesheet:





    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

    xmlns:ng="http://docbook.org/docbook-ng" xmlns:db="http://docbook.org/ns/docbook"

    xmlns:exsl="http://exslt.org/common" version="1.0" exclude-result-prefixes="exsl db ng">



    <xsl:import href="../html/chunk.xsl"/>



    <xsl:template match="/">

    <xsl:call-template name="jstoc"/>

    </xsl:template>



    <xsl:template match="text()" mode="jstoc"/>





    <xsl:template name="jstoc">

    <xsl:call-template name="write.chunk">

    <xsl:with-param name="filename">

    <xsl:if test="$manifest.in.base.dir != 0">

    <xsl:value-of select="$base.dir"/>

    </xsl:if>

    <xsl:value-of select="'toctree.js'"/>

    </xsl:with-param>

    <xsl:with-param name="method" select="'text'"/>

    <xsl:with-param name="encoding" select="'utf-8'"/>

    <xsl:with-param name="indent" select="'yes'"/>

    <xsl:with-param name="content">



    <xsl:text>

    var tree;



    function treeInit() {

    tree = new YAHOO.widget.TreeView("treeDiv1");

    var root = tree.getRoot();

    </xsl:text>



    <xsl:variable name="parent" select="'root'"/>



    <xsl:variable name="title">

    <xsl:apply-templates select="/*" mode="title.markup"/>

    </xsl:variable>

    <xsl:variable name="href">

    <xsl:call-template name="href.target.with.base.dir">

    <xsl:with-param name="object" select="/"/>

    </xsl:call-template>

    </xsl:variable>



    <xsl:variable name="self" select="generate-id()"/>





    <xsl:text>var </xsl:text>

    <xsl:value-of select="concat('obj', $self)"/>

    <xsl:text> = { label: "</xsl:text>

    <xsl:value-of select="$title"/>

    <xsl:text> ", href:"</xsl:text>

    <xsl:value-of select="$href"/>

    <xsl:text>", target:"content"};</xsl:text>



    <xsl:text>var </xsl:text>

    <xsl:value-of select="$self"/>

    <xsl:text> = new YAHOO.widget.TextNode(</xsl:text>

    <xsl:value-of select="concat('obj', $self)"/>

    <xsl:text>, </xsl:text>

    <xsl:value-of select="'root'"/>

    <xsl:text>, false);</xsl:text>



    <xsl:apply-templates select="/*/*" mode="jstoc"/>





    <xsl:text>

    tree.draw();

    }



    YAHOO.util.Event.addListener(window, "load", treeInit);

    </xsl:text>



    </xsl:with-param>

    </xsl:call-template>



    </xsl:template>









    <xsl:template

    match="book|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index"

    mode="jstoc">



    <xsl:variable name="title">

    <xsl:apply-templates select="." mode="title.markup"/>

    </xsl:variable>



    <xsl:variable name="href">

    <xsl:call-template name="href.target.with.base.dir">

    <xsl:with-param name="context" select="/"/>

    </xsl:call-template>

    </xsl:variable>



    <xsl:variable name="jsid" select="generate-id()"/>



    <xsl:text>var </xsl:text>

    <xsl:value-of select="concat('obj', $jsid)"/>

    <xsl:text> = { label: "</xsl:text>

    <xsl:value-of select="$title"/>

    <xsl:text> ", href:"</xsl:text>

    <xsl:value-of select="$href"/>

    <xsl:text>", target:"content"};</xsl:text>



    <xsl:text>var </xsl:text>

    <xsl:value-of select="$jsid"/>

    <xsl:text> = new YAHOO.widget.TextNode(</xsl:text>

    <xsl:value-of select="concat('obj', $jsid)"/>

    <xsl:text>, </xsl:text>





    <xsl:value-of select="'root'"/>

    <xsl:text>, false);</xsl:text>



    <xsl:apply-templates

    select="part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index"

    mode="jstoc"/>

    </xsl:template>



    <xsl:template match="text()" mode="jstoc"/>



    </xsl:stylesheet>





    Any ideas are very appreciated.



    Greetings,

    Pavel Škopík












  • 4.  RE: [docbook-apps] generating javascript navigation

    Posted 04-17-2008 10:21
    Hello,

    It seems that I have figured it out. The stylesheet bellow now generates the file with javascript tree contaning the table of contents.

    Greetings,
    Pavel Škopík

    <xsl:import href="chunk.xsl"/>

    <xsl:template match="/">
    <xsl:choose>
    <xsl:when
    test="(function-available('exsl:node-set') or
    contains(system-property('xsl:vendor'),
    'Apache Software Foundation'))
    and (*/self::ng:* or */self::db:*)">
    <xsl:call-template name="log.message">
    <xsl:with-param name="level">Note</xsl:with-param>
    <xsl:with-param name="context-desc">
    <xsl:text>namesp. cut</xsl:text>
    </xsl:with-param>
    <xsl:with-param name="message">
    <xsl:text>stripped namespace before processing</xsl:text>
    </xsl:with-param>
    </xsl:call-template>
    <xsl:variable name="nons">
    <xsl:apply-templates mode="stripNS"/>
    </xsl:variable>
    <xsl:call-template name="log.message">
    <xsl:with-param name="level">Note</xsl:with-param>
    <xsl:with-param name="context-desc">
    <xsl:text>namesp. cut</xsl:text>
    </xsl:with-param>
    <xsl:with-param name="message">
    <xsl:text>processing stripped document</xsl:text>
    </xsl:with-param>
    </xsl:call-template>
    <xsl:apply-templates select="exsl:node-set($nons)"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:choose>
    <xsl:when test="$rootid != ''">
    <xsl:choose>
    <xsl:when test="count(key('id',$rootid)) = 0">
    <xsl:message terminate="yes">
    <xsl:text>ID '</xsl:text>
    <xsl:value-of select="$rootid"/>
    <xsl:text>' not found in document.</xsl:text>
    </xsl:message>
    </xsl:when>
    <xsl:otherwise>
    <xsl:if
    test="$collect.xref.targets = 'yes' or
    $collect.xref.targets = 'only'">
    <xsl:apply-templates select="key('id', $rootid)"
    mode="collect.targets"/>
    </xsl:if>
    <xsl:if test="$collect.xref.targets != 'only'">
    <xsl:message>Formatting from <xsl:value-of select="$rootid"/></xsl:message>
    <xsl:apply-templates select="key('id',$rootid)"
    mode="process.root"/>
    <xsl:call-template name="jstoc"/>
    </xsl:if>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
    <xsl:if
    test="$collect.xref.targets = 'yes' or
    $collect.xref.targets = 'only'">
    <xsl:apply-templates select="/" mode="collect.targets"/>
    </xsl:if>
    <xsl:if test="$collect.xref.targets != 'only'">
    <xsl:apply-templates select="/" mode="process.root"/>
    <xsl:call-template name="jstoc"/>
    </xsl:if>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    <xsl:template match="text()" mode="jstoc"/>


    <xsl:template name="jstoc">
    <xsl:call-template name="write.chunk">
    <xsl:with-param name="filename">
    <xsl:if test="$manifest.in.base.dir != 0">
    <xsl:value-of select="$base.dir"/>
    </xsl:if>
    <xsl:value-of select="'toctree.js'"/>
    </xsl:with-param>
    <xsl:with-param name="method" select="'text'"/>
    <xsl:with-param name="encoding" select="'windows-1250'"/>
    <xsl:with-param name="indent" select="'yes'"/>
    <xsl:with-param name="content">


    <xsl:text>
    var tree;

    function treeInit() {
    tree = new YAHOO.widget.TreeView("treeDiv1");
    var root = tree.getRoot();
    </xsl:text>



    <xsl:apply-templates mode="jstoc"/>
    <xsl:text>
    tree.draw();
    }

    YAHOO.util.Event.addListener(window, "load", treeInit);
    </xsl:text>
    </xsl:with-param>
    </xsl:call-template>
    </xsl:template>



    <xsl:template match="book|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index" mode="jstoc">

    <xsl:param name="current.node" select="."/>

    <xsl:variable name="objID" select="generate-id()"/>


    <xsl:variable name="parentID">
    <xsl:if test="$current.node = /">
    <xsl:value-of select="'root'"/>
    </xsl:if>
    <xsl:if test="$current.node != /">
    <xsl:value-of select="generate-id(parent::*)"/>
    </xsl:if>
    </xsl:variable>

    <xsl:variable name="title">
    <xsl:apply-templates select="." mode="title.markup"/>
    </xsl:variable>


    <xsl:variable name="href">
    <xsl:call-template name="href.target.with.base.dir">
    <xsl:with-param name="context" select="/"/>
    </xsl:call-template>
    </xsl:variable>


    <xsl:text>var </xsl:text>
    <xsl:value-of select="concat('obj', $objID)"/>
    <xsl:text> = { label: "</xsl:text>
    <xsl:value-of select="normalize-space($title)"/>
    <xsl:text>", href:"</xsl:text>
    <xsl:value-of select="$href"/>
    <xsl:text>", target:"content"};</xsl:text>

    <xsl:text>var </xsl:text>
    <xsl:value-of select="$objID"/>
    <xsl:text> = new YAHOO.widget.TextNode(</xsl:text>
    <xsl:value-of select="concat('obj', $objID)"/>
    <xsl:text>, </xsl:text>
    <xsl:value-of select="$parentID"/>
    <xsl:text>, false);</xsl:text>
    <xsl:apply-templates mode="jstoc" select="book|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index"/>
    </xsl:template>



  • 5.  RE: [docbook-apps] generating javascript navigation

    Posted 04-17-2008 15:39
    What else do you have to do to use this? Is there an example of the output I could look at?

    Thanks,
    David

    ________________________________

    From: Skopik Pavel [mailto:Pavel.Skopik@aipsafe.cz]
    Sent: Thursday, April 17, 2008 5:21 AM
    To: docbook-apps@lists.oasis-open.org
    Subject: RE: [docbook-apps] generating javascript navigation


    Hello,

    It seems that I have figured it out. The stylesheet bellow now generates the file with javascript tree contaning the table of contents.

    Greetings,
    Pavel Škopík

    <xsl:import href="chunk.xsl"/>

    <xsl:template match="/">
    <xsl:choose>
    <xsl:when
    test="(function-available('exsl:node-set') or
    contains(system-property('xsl:vendor'),
    'Apache Software Foundation'))
    and (*/self::ng:* or */self::db:*)">
    <xsl:call-template name="log.message">
    <xsl:with-param name="level">Note</xsl:with-param>
    <xsl:with-param name="context-desc">
    <xsl:text>namesp. cut</xsl:text>
    </xsl:with-param>
    <xsl:with-param name="message">
    <xsl:text>stripped namespace before processing</xsl:text>
    </xsl:with-param>
    </xsl:call-template>
    <xsl:variable name="nons">
    <xsl:apply-templates mode="stripNS"/>
    </xsl:variable>
    <xsl:call-template name="log.message">
    <xsl:with-param name="level">Note</xsl:with-param>
    <xsl:with-param name="context-desc">
    <xsl:text>namesp. cut</xsl:text>
    </xsl:with-param>
    <xsl:with-param name="message">
    <xsl:text>processing stripped document</xsl:text>
    </xsl:with-param>
    </xsl:call-template>
    <xsl:apply-templates select="exsl:node-set($nons)"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:choose>
    <xsl:when test="$rootid != ''">
    <xsl:choose>
    <xsl:when test="count(key('id',$rootid)) = 0">
    <xsl:message terminate="yes">
    <xsl:text>ID '</xsl:text>
    <xsl:value-of select="$rootid"/>
    <xsl:text>' not found in document.</xsl:text>
    </xsl:message>
    </xsl:when>
    <xsl:otherwise>
    <xsl:if
    test="$collect.xref.targets = 'yes' or
    $collect.xref.targets = 'only'">
    <xsl:apply-templates select="key('id', $rootid)"
    mode="collect.targets"/>
    </xsl:if>
    <xsl:if test="$collect.xref.targets != 'only'">
    <xsl:message>Formatting from <xsl:value-of select="$rootid"/></xsl:message>
    <xsl:apply-templates select="key('id',$rootid)"
    mode="process.root"/>
    <xsl:call-template name="jstoc"/>
    </xsl:if>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
    <xsl:if
    test="$collect.xref.targets = 'yes' or
    $collect.xref.targets = 'only'">
    <xsl:apply-templates select="/" mode="collect.targets"/>
    </xsl:if>
    <xsl:if test="$collect.xref.targets != 'only'">
    <xsl:apply-templates select="/" mode="process.root"/>
    <xsl:call-template name="jstoc"/>
    </xsl:if>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    <xsl:template match="text()" mode="jstoc"/>


    <xsl:template name="jstoc">
    <xsl:call-template name="write.chunk">
    <xsl:with-param name="filename">
    <xsl:if test="$manifest.in.base.dir != 0">
    <xsl:value-of select="$base.dir"/>
    </xsl:if>
    <xsl:value-of select="'toctree.js'"/>
    </xsl:with-param>
    <xsl:with-param name="method" select="'text'"/>
    <xsl:with-param name="encoding" select="'windows-1250'"/>
    <xsl:with-param name="indent" select="'yes'"/>
    <xsl:with-param name="content">


    <xsl:text>
    var tree;

    function treeInit() {
    tree = new YAHOO.widget.TreeView("treeDiv1");
    var root = tree.getRoot();
    </xsl:text>



    <xsl:apply-templates mode="jstoc"/>
    <xsl:text>
    tree.draw();
    }

    YAHOO.util.Event.addListener(window, "load", treeInit);
    </xsl:text>
    </xsl:with-param>
    </xsl:call-template>
    </xsl:template>



    <xsl:template match="book|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index" mode="jstoc">

    <xsl:param name="current.node" select="."/>

    <xsl:variable name="objID" select="generate-id()"/>


    <xsl:variable name="parentID">
    <xsl:if test="$current.node = /">
    <xsl:value-of select="'root'"/>
    </xsl:if>
    <xsl:if test="$current.node != /">
    <xsl:value-of select="generate-id(parent::*)"/>
    </xsl:if>
    </xsl:variable>

    <xsl:variable name="title">
    <xsl:apply-templates select="." mode="title.markup"/>
    </xsl:variable>


    <xsl:variable name="href">
    <xsl:call-template name="href.target.with.base.dir">
    <xsl:with-param name="context" select="/"/>
    </xsl:call-template>
    </xsl:variable>


    <xsl:text>var </xsl:text>
    <xsl:value-of select="concat('obj', $objID)"/>
    <xsl:text> = { label: "</xsl:text>
    <xsl:value-of select="normalize-space($title)"/>
    <xsl:text>", href:"</xsl:text>
    <xsl:value-of select="$href"/>
    <xsl:text>", target:"content"};</xsl:text>

    <xsl:text>var </xsl:text>
    <xsl:value-of select="$objID"/>
    <xsl:text> = new YAHOO.widget.TextNode(</xsl:text>
    <xsl:value-of select="concat('obj', $objID)"/>
    <xsl:text>, </xsl:text>
    <xsl:value-of select="$parentID"/>
    <xsl:text>, false);</xsl:text>
    <xsl:apply-templates mode="jstoc" select="book|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index"/>
    </xsl:template>



  • 6.  RE: [docbook-apps] generating javascript navigation

    Posted 04-17-2008 19:36
    Nevermind. I see the link now in your previous message. Neat :-)

    Thanks,
    David

    ________________________________

    From: David Cramer
    Sent: Thursday, April 17, 2008 10:39 AM
    To: Skopik Pavel; docbook-apps@lists.oasis-open.org
    Subject: RE: [docbook-apps] generating javascript navigation


    What else do you have to do to use this? Is there an example of the output I could look at?

    Thanks,
    David

    ________________________________

    From: Skopik Pavel [mailto:Pavel.Skopik@aipsafe.cz]
    Sent: Thursday, April 17, 2008 5:21 AM
    To: docbook-apps@lists.oasis-open.org
    Subject: RE: [docbook-apps] generating javascript navigation


    Hello,

    It seems that I have figured it out. The stylesheet bellow now generates the file with javascript tree contaning the table of contents.

    Greetings,
    Pavel Škopík

    <xsl:import href="chunk.xsl"/>

    <xsl:template match="/">
    <xsl:choose>
    <xsl:when
    test="(function-available('exsl:node-set') or
    contains(system-property('xsl:vendor'),
    'Apache Software Foundation'))
    and (*/self::ng:* or */self::db:*)">
    <xsl:call-template name="log.message">
    <xsl:with-param name="level">Note</xsl:with-param>
    <xsl:with-param name="context-desc">
    <xsl:text>namesp. cut</xsl:text>
    </xsl:with-param>
    <xsl:with-param name="message">
    <xsl:text>stripped namespace before processing</xsl:text>
    </xsl:with-param>
    </xsl:call-template>
    <xsl:variable name="nons">
    <xsl:apply-templates mode="stripNS"/>
    </xsl:variable>
    <xsl:call-template name="log.message">
    <xsl:with-param name="level">Note</xsl:with-param>
    <xsl:with-param name="context-desc">
    <xsl:text>namesp. cut</xsl:text>
    </xsl:with-param>
    <xsl:with-param name="message">
    <xsl:text>processing stripped document</xsl:text>
    </xsl:with-param>
    </xsl:call-template>
    <xsl:apply-templates select="exsl:node-set($nons)"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:choose>
    <xsl:when test="$rootid != ''">
    <xsl:choose>
    <xsl:when test="count(key('id',$rootid)) = 0">
    <xsl:message terminate="yes">
    <xsl:text>ID '</xsl:text>
    <xsl:value-of select="$rootid"/>
    <xsl:text>' not found in document.</xsl:text>
    </xsl:message>
    </xsl:when>
    <xsl:otherwise>
    <xsl:if
    test="$collect.xref.targets = 'yes' or
    $collect.xref.targets = 'only'">
    <xsl:apply-templates select="key('id', $rootid)"
    mode="collect.targets"/>
    </xsl:if>
    <xsl:if test="$collect.xref.targets != 'only'">
    <xsl:message>Formatting from <xsl:value-of select="$rootid"/></xsl:message>
    <xsl:apply-templates select="key('id',$rootid)"
    mode="process.root"/>
    <xsl:call-template name="jstoc"/>
    </xsl:if>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
    <xsl:if
    test="$collect.xref.targets = 'yes' or
    $collect.xref.targets = 'only'">
    <xsl:apply-templates select="/" mode="collect.targets"/>
    </xsl:if>
    <xsl:if test="$collect.xref.targets != 'only'">
    <xsl:apply-templates select="/" mode="process.root"/>
    <xsl:call-template name="jstoc"/>
    </xsl:if>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    <xsl:template match="text()" mode="jstoc"/>


    <xsl:template name="jstoc">
    <xsl:call-template name="write.chunk">
    <xsl:with-param name="filename">
    <xsl:if test="$manifest.in.base.dir != 0">
    <xsl:value-of select="$base.dir"/>
    </xsl:if>
    <xsl:value-of select="'toctree.js'"/>
    </xsl:with-param>
    <xsl:with-param name="method" select="'text'"/>
    <xsl:with-param name="encoding" select="'windows-1250'"/>
    <xsl:with-param name="indent" select="'yes'"/>
    <xsl:with-param name="content">


    <xsl:text>
    var tree;

    function treeInit() {
    tree = new YAHOO.widget.TreeView("treeDiv1");
    var root = tree.getRoot();
    </xsl:text>



    <xsl:apply-templates mode="jstoc"/>
    <xsl:text>
    tree.draw();
    }

    YAHOO.util.Event.addListener(window, "load", treeInit);
    </xsl:text>
    </xsl:with-param>
    </xsl:call-template>
    </xsl:template>



    <xsl:template match="book|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index" mode="jstoc">

    <xsl:param name="current.node" select="."/>

    <xsl:variable name="objID" select="generate-id()"/>


    <xsl:variable name="parentID">
    <xsl:if test="$current.node = /">
    <xsl:value-of select="'root'"/>
    </xsl:if>
    <xsl:if test="$current.node != /">
    <xsl:value-of select="generate-id(parent::*)"/>
    </xsl:if>
    </xsl:variable>

    <xsl:variable name="title">
    <xsl:apply-templates select="." mode="title.markup"/>
    </xsl:variable>


    <xsl:variable name="href">
    <xsl:call-template name="href.target.with.base.dir">
    <xsl:with-param name="context" select="/"/>
    </xsl:call-template>
    </xsl:variable>


    <xsl:text>var </xsl:text>
    <xsl:value-of select="concat('obj', $objID)"/>
    <xsl:text> = { label: "</xsl:text>
    <xsl:value-of select="normalize-space($title)"/>
    <xsl:text>", href:"</xsl:text>
    <xsl:value-of select="$href"/>
    <xsl:text>", target:"content"};</xsl:text>

    <xsl:text>var </xsl:text>
    <xsl:value-of select="$objID"/>
    <xsl:text> = new YAHOO.widget.TextNode(</xsl:text>
    <xsl:value-of select="concat('obj', $objID)"/>
    <xsl:text>, </xsl:text>
    <xsl:value-of select="$parentID"/>
    <xsl:text>, false);</xsl:text>
    <xsl:apply-templates mode="jstoc" select="book|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index"/>
    </xsl:template>



  • 7.  RE: [docbook-apps] generating javascript navigation

    Posted 04-21-2008 06:51
    Hi,

    you can have a look at our website: http://www.aipsafe.cz/files/tutorial/frame.html <http://www.aipsafe.cz/files/tutorial/frame.html> .

    Greetings,
    Pavel