Docbook - suppressing TOC - html

I am converting a docbook to an html using 1.77 xsl transformation. But when it is transformed it automatically generates a Table of Contents. How do you change this behavior?
I have found this: Disable table of contents for documents
So I am guessing that html xsl transform would be the presentation system?

Elaborate DocBook formatting is meant to be customized using an xsl stylesheet.
See Also
Writing a DocBOok Customization Layer for Formatting
Customizing Table Of Contents Using XSL
customize_formatting.xsl: Example DocBook XSL Customization Layer
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0"> <!-- change this to 2.0 if your tools support it -->
<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl"/>
<!--uncomment this to suppress toc when using XSL 1.0 or 2.0
<xsl:param name="generate.toc">article</xsl:param>
<xsl:param name="generate.toc">book</xsl:param>
-->
<!--uncomment this to suppress toc when using XSL 2.0
<xsl:param name="generate.toc">
article nop
book nop
</xsl:param>
-->
</xsl:stylesheet>
How to Use customize_formatting.xsl
Point your tools to use customize_formatting.xsl instead of the off-the-shelf docbook.xsl. Then, put all your formatting customizations in the body of the <xsl:stylesheet> section.
For TOC suppression, you can just uncomment the appropriate line.
There is a quirk with some (or maybe all) XSL 1.0 tools that seem to prevent them from handling the whitespace-separated pairs used in the body of <xsl:param name="generate.toc">. I have had success suppressing TOC by just using the single word article or book instead of the proper whitespace separated pairs.

When transforming, you can use the Transformer#setParameter(String, Object) method to specify no TOC generation like this:
transformer.setParameter("generate.toc", "nop");

Related

XSL applying tags incorrectly

I have a class project I'm working on but I've hit a point where I'm stuck and don't know what to do. My XSL (style6.xsl) works to an extent but it creates text instead of wrapping a chunk of my xml (Project6style.xml) so I have 2 sets of text but one isn't wrapped in any tags. I've spent all day trying to figure out why it's been doing this but I can't figure it out. I was hoping someone would be able to take a look at it.
If anyone could help it would be appreciated!
https://www.mediafire.com/?4b74nb1iltdqsqx
File Reference:
style6.xsl (what I need to edit so it looks a certain way)
Project6style.xml (what was given to me in the class project folder)
Tutorial.06 Project.doc (The assignment word document)
XSL Current Output.html (what my current xsl file is giving me)
XSL Output - WHAT IT SHOULD BE.html (What I'm assuming my professor wants it to look like)
Code for those who don't want to download:
XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0"/>
<xsl:template match="project">
<html>
<body>
<xsl:apply-templates/>
<h1>
<xsl:value-of select="student"/>
</h1>
<h2>
<xsl:value-of select="date"/>
</h2>
</body>
</html>
</xsl:template>
<xsl:template match="objective">
<xsl:apply-templates/>
<h4>
<xsl:value-of select=".//name"/>
</h4>
<div>
<xsl:value-of select="description"/>
</div>
</xsl:template>
</xsl:stylesheet>
XML:
<?xml version="1.0"?>
<!-- XML Project 6 -->
<?xml-stylesheet type="text/xsl" href="style6.xsl" ?>
<project>
<student>Student</student>
<date>Date</date>
<objective>
<name>Working with XSL</name>
<description>XSL is composed of three parts: XSL-FO
(Extensible Style sheet Language - Formatting Objects),
XSLT (Extensible Style sheet Language Transformations),
and XPath. XSL-FO is used to implement page layout and design.
XSLT is used to transform XML content into another presentation format.
XPath is used to locate information from an XML document
and perform operations and calculations upon that content.
</description>
</objective>
<objective>
<name>Introducing XSLT style sheets and processors</name>
<description>An XSLT style sheet contains instructions for transforming
the contents of an XML document into another format. An XSLT style
sheet document is itself an XML document, but has an extension .xsl.
An XSLT style sheet converts a source document of XML content into
a result document containing the markup codes and other instructions
for formatting.
</description>
</objective>
<objective>
<name>Creating an XSLT style sheet</name>
<description>To attach an XML file to the style sheet,
insert the processing instruction following the first line
in the document. An XSLT style sheet has the general structure
of all XML documents.
</description>
</objective>
</project>
HTML result (What my HTML file displays with these 2 files in their current state):
Student
Date
Working with XSL
XSL is composed of three parts: XSL-FO
(Extensible Style sheet Language - Formatting Objects),
XSLT (Extensible Style sheet Language Transformations),
and XPath. XSL-FO is used to implement page layout and design.
XSLT is used to transform XML content into another presentation format.
XPath is used to locate information from an XML document
and perform operations and calculations upon that content.
<h4>Working with XSL</h4><div>XSL is composed of three parts: XSL-FO
(Extensible Style sheet Language - Formatting Objects),
XSLT (Extensible Style sheet Language Transformations),
and XPath. XSL-FO is used to implement page layout and design.
XSLT is used to transform XML content into another presentation format.
XPath is used to locate information from an XML document
and perform operations and calculations upon that content.
</div>
Introducing XSLT style sheets and processors
An XSLT style sheet contains instructions for transforming
the contents of an XML document into another format. An XSLT style
sheet document is itself an XML document, but has an extension .xsl.
An XSLT style sheet converts a source document of XML content into
a result document containing the markup codes and other instructions
for formatting.
<h4>Introducing XSLT style sheets and processors</h4><div>An XSLT style sheet contains instructions for transforming
the contents of an XML document into another format. An XSLT style
sheet document is itself an XML document, but has an extension .xsl.
An XSLT style sheet converts a source document of XML content into
a result document containing the markup codes and other instructions
for formatting.
</div>
Creating an XSLT style sheet
To attach an XML file to the style sheet,
insert the processing instruction following the first line
in the document. An XSLT style sheet has the general structure
of all XML documents.
<h4>Creating an XSLT style sheet</h4><div>To attach an XML file to the style sheet,
insert the processing instruction following the first line
in the document. An XSLT style sheet has the general structure
of all XML documents.
</div>
<h1>Student</h1><h2>Date</h2>
This is one possible stylesheet, merely sticking to the structure of the input XML document:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" />
<xsl:template match="objective">
<h4><xsl:value-of select="name" /></h4>
<div><xsl:value-of select="description" /></div>
</xsl:template>
<xsl:template match="project">
<h1><xsl:value-of select="student" /></h1>
<h2><xsl:value-of select="date" /></h2>
<xsl:apply-templates select="objective" />
</xsl:template>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="project" />
</body>
</html>
</xsl:template>
</xsl:stylesheet>
note: I like to be specific about the target(s) of my apply-templates elements (hence the select="..." attribute), while some people prefer implicit selection; the choice is entirely up to you.

How to get html as xml for XSLT conversion usage?

I would like to do some XSLT conversion with the HTML page with YQL. The following line is used to get HTML:
select * from html where url="http://example.com/somepage" and
xpath='//div[#class="article-text"]'
How can I apply select * from xslt where ... to the previous result?
Not sure as I haven't used YQL before, but I guess you have to go the other way round: using XSLT to get the result out of the HTML and than apply the YQL-Query to get the XML as result:
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:apply-templates select="//div[#class='article-text']" />
</xsl:template>
<xsl:template match="div[#class='article-text']">
<articletext>
<xsl:value-of select="."/>
</articletext>
</xsl:template>
YQL query:
select * from xslt where stylesheet="url/name-of.xsl" and
url="http://example.com/somepage"
This should result in
<results>
<articletext>Text of article</articletext>
</results>
As I don't know YQL but was used working with XSLT/XPath, I just googled about it and found this recommendable SO example: YQL column projection using XPATH . Instead of just pasting the link I adjusted the XSLT-Part of the example provided there to match your query.
Note that HTML is not an XML-based language (though XHTML is). If you want to operate on HTML using XML tools, you will need to either find an HTML parser (such as nekohtml, which is based on Apache Xerces) or preconvert the HTML to XHTML using something like the W3C's tidy tool.

Transform XML in web browser via two transformations to HTML

I tried to transform a XML document within a web browser to HTML via two XSL transformations.
Long story short: XML => XML => HTML
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<?xml-stylesheet type="text/xsl" href="enrich.xsl" ?>
<?xml-stylesheet type="text/xsl" href="overview.xsl" ?>
<project></project>
The first XSL should add some elements to the XML,
the second XSL should transform the result from the first step to HTML.
My target is to get HTML displayed at the end.
Both XSL are transformed separately.
It seems to me that Safari, Firefox and Chrome do not execute more than one processing instruction. Is this true, or am i missing something?
I never tried to execute two seperate transformations in a web browser, but you may try this kind of patterns to do "2 transforms in 1" (this only works with XSLT 2.0, cause of the variable structure) :
<xsl:template match="/">
<!-- You use a variable to store the result of the first transformation.-->
<xsl:variable name="result1">
<!-- You use a mode called transform1 (or whatever) to distinct templates for
transform1 from those of transform2-->
<xsl:apply-templates select="*" mode="transform1"/>
</xsl:variable>
<!-- You execute the second transform on the result variable (you could use a
mode to formally distinct the template from transform2, or you could use default
mode for them) -->
<xsl:apply-templates select="$result1"/>

MSXSL Error and barely any output

I am trying to transform some HTML files to my own XML-format via XSL.
For this purpose I use HTML Tidy to clean up the input files, then transform them to xhtml with html2xhtml and then use a xsl script with msxsl to transform the xhtml files to my own format.
However, the last step is failing with not a error message at all (it is a semantical fail; not a technical ;-)): My output file just contains empty tags.
I had a problem like this before and removed the xmlns attribute from the html tag, what causes nearly all of the online transformers to work with my files correctly. MSXSL now writes the following error message: "Use of default namespace declaration attribute in DTD not supported".
Find the files I use here: http://pastie.org/5483087
Thank you in advance!
Well that is the FAQ with XSLT and XPath 1.0, the elements in your input XHTML document are in a namespace and your XSLT does not take that into account. You need to change it to e.g.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xhtml">
<xsl:template match="/">
<stellenausschreibung>
<hochschule><xsl:value-of select="//xhtml:div[#id='contentText']/xhtml:img/#alt" /></hochschule>
<anbieter><xsl:value-of select="//xhtml:p[#id='ad_employer']" /></anbieter>
<typ><xsl:value-of select="//xhtml:h1" /></typ>
<bewerbungsschluss><xsl:value-of select="//xhtml:span[#id='ad_bewerbungsschluss']" /></bewerbungsschluss>
<erscheinungsdatum><xsl:value-of select="//xhtml:span[#class='job_published_at']" /></erscheinungsdatum>
<inhalt><xsl:value-of select="//xhtml:p[#id='ad_job']" /></inhalt>
</stellenausschreibung>
</xsl:template>
</xsl:stylesheet>
The prefix (in my example xhtml) for the XHTML namespace used in the stylesheet can of course be freely chosen but it is necessary to use one as with XSLT/XPath 1.0 a path of e.g. //p always selects p elements in no namespace.

DocBook: How to link to another man page?

I am writing a couple of man pages in DocBook. I would also like to convert them to HTML for display on the web. How can I insert a link from one man page to another, such that it appears in man as target(1) but appears on the web as a hyperlink to the other man page, which has also been converted to a separate HTML file in the same directory?
I think I have figured this out. You should use a <citerefentry/> in the document, which appears as expected in a man page. It isn't hyperlinked in a HTML document unless you provide a method for generating the target URL, which you do in a customisation layer.
Here is an example document snippet for the "See Also" section in a man page:
<refsect1 id="seealso">
<title>See Also</title>
<simplelist type="inline">
<member><citerefentry><refentrytitle>grep</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
<member><citerefentry><refentrytitle>awk</refentrytitle><manvolnum>1P</manvolnum></citerefentry></member>
</simplelist>
</refsect1>
Coupled with this customisation template (saved as custom.xsl)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- Ignore spaces between elements (without this, the URL is "grep .html" -->
<xsl:strip-space elements="*"/>
<!-- Turn citerefentry elements into HTML links -->
<xsl:param name="citerefentry.link" select="1"/>
<!-- Code to generate the URL for a given citerefentry element -->
<xsl:template name="generate.citerefentry.link">
<xsl:value-of select="refentrytitle"/>
<xsl:text>.html</xsl:text>
</xsl:template>
</xsl:stylesheet>
Using the xmlto program to process the DocBook XML, specifying the customisation layer for HTML:
$ xmlto man input.xml
$ xmlto html-nochunks -m custom.xsl input.xml
In a manpage, this produces:
SEE ALSO
grep(1), awk(1P)
And in HTML it produces this: (all the <span> elements have been removed for clarity)
<h2>See Also</h2>
grep(1), awk(1)
The actual URLs generated can be adjusted by editing the content of the generate.citerefentry.link template in custom.xsl. The example above just uses the value of the <refentrytitle> from the DocBook XML and appends ".html" to it.