DocBook: How to link to another man page? - html

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.

Related

XSLT: What is the best way to apply a floating text that will display the full expression for acronyms from an external dictionary file?

I'm new to XSLT.
I need to apply floating text that displays a setting for acronyms, as soon as the mouse cursor hovers over a word that is abbreviated.
My input file is XML, and every word that should display acronyms is represented in the following format:
<abbreviation Id="E.G."/>
When the mouse cursor hovers over the word EG, the floating text will be displayed: "for example".
I thought to apply the floating text using the HTML abbr tag
And the code I wrote is:
<xsl:template match="abbreviation">
<abbr title="for example.">
<xsl:value-of select="#Id"/>
</abbr>
</xsl:template>
I want the "title" attribute to be given as a parameter the definition of the main boxes from an external file that will contain a dictionary of related abbreviations and explanations.
I would love to know how to apply my issue.
And also get ideas about the external dictionary file - what kind of file should you create? For example, I would like a good structure of the file.
Note:
I use OXYGEN EDITOR,
And I believe I can also get solutions in XSLT version 2 and 3
Suppose your external dictionary looks like:
dict.xml
<dictionary>
<entry abbr="C.V.">course of life</entry>
<entry abbr="E.G.">for example</entry>
<entry abbr="N.B.">note well</entry>
</dictionary>
You can then use a key to transform an input like:
XML
<root>
<abbreviation Id="E.G."/>
</root>
using:
XSLT 2.0 (untested)
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="path-to-dictionary" select="'dict.xml'"/>
<xsl:key name="abbr-lookup" match="entry" use="#abbr" />
<xsl:template match="/root">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="abbreviation">
<abbr title="{key('abbr-lookup', #Id, document($path-to-dictionary))}">
<xsl:value-of select="#Id"/>
</abbr>
</xsl:template>
</xsl:stylesheet>
to get:
Result
<html>
<body>
<abbr title="for example">E.G.</abbr>
</body>
</html>
To understand the syntax used, read about Attribute Value Templates.
Well, XSLT does not float any text, it is a programming language to transform XML (or with XSLT 2 or 3, other input formats) to XML, (X)HTML, plain text. You seem to want to transform your XML to HTML in the hope the HTML user agent or browser displays a tooltip of the title attribute.
As for using an XML file as a secondary input file, if you have abbrvs.xml with
<root><abbr key="E.G.">for example.</abbr>...</root>
then in XSLT you can use
<abbr title="{key('abbr', #Id, doc('abbrvs.xml'))}">
<xsl:value-of select="#id"/>
</abbr>
to pull that title attribute value from the secondary input file if the XSLT declares a key
<xsl:key name="abbr" match="abbr" use="#key"/>

CSS animations stop working when XML file is transformed in XSLT

I have a page, with multiple animations on it. If I save it as an html file and run it in a browser, it works as it should, but has no information as I have no imported the xml document. When I add in my xml, by using xslt transformation, and save it as xsl not html, the animations will no longer run, and I'm lost as to why this is happening.
I use
<?xml-stylesheet type="text/xsl" href="blog.xsl" ?>
to connect my xml file with the xslt, and then in xml use
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
</html>
Any help as to why it's not working as xslt but is as html would be hugely appreciated.
Thanks.
Edit:
<?xml version='1.0' encoding="UTF-8"?>
<!DOCTYPE blog SYSTEM "blog.dtd">
<?xml-stylesheet type="text/xsl" href="blog.xsl"?>
<blog>
<blogPost>
<postTitle> First Test Post </postTitle>
<postText> This is a test post </postText>
<postImage></postImage>
<postQuote> Happiness can be found even in the darkest of times if one only remembers to turn on the light </postQuote>
<postLink> www.pandora.net </postLink>
<postAudio></postAudio>
<postVideo></postVideo>
<postChat></postChat>
<postDate> 12th June </postDate>
<postTags> FirstPost New </postTags>
</blogPost>
<blogPost>
<postTitle> Post Two </postTitle>
<postText> This is a another test post </postText>
<postImage></postImage>
<postQuote> Never let the fear of striking out keep you from
playing the game</postQuote>
<postLink> www.surfdome.com </postLink>
<postAudio></postAudio>
<postVideo></postVideo>
<postChat></postChat>
<postDate> 12th June </postDate>
<postTags> FirstPost New </postTags>
</blogPost>
</blog>

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.

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"/>

Docbook - suppressing TOC

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");