I have the following Docbook 5.1 document
<?xml version="1.0" encoding="UTF-8"?>
<book xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="5.1">
<info>
<title>Test</title>
</info>
<chapter>
<title>Switchs of <systemitem class="domainname">corp.net</systemitem></title>
<para>
Switchs: <systemitem class="fqdomainname">switch-<replaceable>id</replaceable>.corp.net</systemitem>.
</para>
</chapter>
</book>
And I use the following customization stylesheet
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="http://docbook.sourceforge.net/release/xsl-ns/current/fo/profile-docbook.xsl"/>
<xsl:param name="monospace.font.family">Liberation Mono</xsl:param>
<xsl:attribute-set name="monospace.properties">
<!-- XXX -->
</xsl:attribute-set>
</xsl:stylesheet>
Unfortunately, the monospace font I use is too large, so I want to reduce
it down to 85% of the serif font's size.
The first thing I tried was
<xsl:attribute name="font-size">0.85em</xsl:attribute>
It worked well except when there is nested monospaced text. In this case, the inner one
is too small.
Then I tried
<xsl:attribute name="font-size">
<xsl:value-of select="$body.font.master * 0.85"/>
<xsl:text>pt</xsl:text>
</xsl:attribute>
It doesn't work when the monospaced text is "inside" a larger sized text (eg. titles).
I've read http://docbook.sourceforge.net/release/xsl/1.78.1/doc/fo/monospace.properties.html, that recommends to use font-size-adjust, but FOP 2.3 doesn't support it.
Is there a way to simulate the font-size-adjust behavior ?
Related
I cannot get docbook tool chain to do the hard page break
as described at the end of http://www.sagehill.net/docbookxsl/PageBreaking.html
(I used to have this working for me but seem to have lost the mojo.)
Here is the script to invoke docbook and saxon
#!/bin/sh
export CLASSPATH=/home/leffstudent/saxon-6.0.1.jar:/home/leffstudent/docbook-sl-1.79.1/saxon65.jar
echo $CLASSPATH
java com.icl.saxon.StyleSheet \
-o $1.fo $1 stO.xsl \
use.extensions=1 default.table.width=auto title.margin.left=0pc insert.xref.page.number=yes
(stO.xsl also sets my ref parameters on how xref should display page numbers. That is
not working, either. Thus, I suspect that my invocation of com.icl.saxon.Stylesheet
is ignoring my customization link
Here is the test docbook file I tried. (The real files is a 500 page
class notes.)
<section><title> </title>
<para>
abc
</para>
<?hard-pagebreak?>
<para>
def
</para>
</section>
Here is the style sheet, stO.xsl
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
<xsl:import href="./titlepage.xsl"/>
<xsl:import href="/home/leffstudent/docbook-xsl-1.79.1/fo/docbook.xsl"/>
<xsl:template match="processing-instruction('hard-pagebreak')">
<fo:block break-after='page'/>
</xsl:template>
<xsl:attribute-set name="formal.object.properties">
<xsl:attribute name="keep-together.within-column">auto</xsl:attribute>
</xsl:attribute-set>
<xsl:param name="local.l10n.xml" select="document('')"/>
<l:i18n xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">
<l:l10n language="en">
<l:context name="xref">
<l:template name="section" text="%t on Page Number %p"/>
<l:template name="mediaobject" text="%t on Page Number %p"/>
<l:template name="imageobject" text="%p"/>
</l:context>
<l:context name="xref-number-and-title">
<l:template name="section" text="%t on Page Number %p"/>
<l:template name="imageobject" text="%p"/>
</l:context>
</l:l10n>
</l:i18n>
</xsl:stylesheet>
I got this working finally with XSLTPROC:
#!/bin/sh
xsltproc --output $1.fo sd.xsl $1
It prints a separate page where I have the hard-pagebreak processing instruction.
Here is the customization layer, sd.xsl
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
<xsl:import href="/home/leffstudent/docbook-xsl-1.79.1/fo/docbook.xsl"/>
<xsl:template match="processing-instruction('hard-pagebreak')">
<fo:block break-after='page'/>
</xsl:template>
</xsl:stylesheet>
I have tried again getting my xref's to work with pictures. (That, of course, is
with a larger file than sd.xsl But that is a separate issue, both literally
and figuratively.)
I still have not been able to get this working with Xalan. See
Question 55941299.
I have to check again to see if I can get this to work with saxon.
This is is what I used to use to prepare my class notes.
However, I can prepare out my 530-page class notes with xsltproc with proper page breaks.
I have to make an xsl for an xml output exported from a database. The name tags in xml have a prefix bib followed by a colon (as in bib:), and it was defined in xml. But I still got an xsl compiler error saying bib: is not declared. So I added the declaration in xsl. this time the error went away, but the result comes out zero, and I checked the path that is correct. I also tried to exclude "bib:" prefix in xsl after declaration but got the same zero result. I am new to xsl so I don't know what is wrong here. These are my files. Thanks very much.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<embasexmllist>
<cards items="1">
<bib:card items="0" xmlns:bib="http://elsevier.co.uk/namespaces/2001/bibliotek">-
<bib:cardfields>
<bib:Fulltext>
<bib:DOI>10.1371/journal.pone.0068303</bib:DOI>
</bib:Fulltext>
<bib:Title>Mesothelin Virus-Like Particle Immunization Controls Pancreatic Cancer Growth through CD8+ T Cell Induction and Reduction in the Frequency of CD4+foxp3+ICOS- Regulatory T Cells
</bib:Title>
</bib:cardfields>
</bib:card>
</cards>
</embasexmllist>
XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:bib="http://www.bib.com/xml">
<xsl:output indent="yes" omit-xml-declaration="no"
media-type="application/xml" encoding="UTF-8" />
<xsl:template match="/">
<searchresult>
<xsl:apply-templates
select="/embasexmllist/cards/bib:card/bib:cardfields" />
</searchresult>
</xsl:template>
<xsl:template match="bib:cardfields">
<document>
<title><xsl:value-of select="bib:Title" /></title>
<snippet>
<xsl:value-of select="bib:Title" />
</snippet>
<url>
<xsl:variable name="doi" select="bib:Fulltext/bib:DOI"/>
<xsl:value-of
select="concat('http://dx.doi.org/', $doi)" />
</url>
</document>
</xsl:template>
</xsl:stylesheet>
The prefix defines a namespace for the XML elements.
For your stylesheet to work, the namespace declaration needs to match that in your input XML. Replace
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:bib="http://www.bib.com/xml">
with
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:bib="http://elsevier.co.uk/namespaces/2001/bibliotek">
This results in the following output XML:
<?xml version="1.0" encoding="utf-8"?>
<searchresult xmlns:bib="http://elsevier.co.uk/namespaces/2001/bibliotek">
<document>
<title>
Mesothelin Virus-Like Particle Immunization Controls Pancreatic Cancer Growth through CD8+ T Cell Induction and Reduction in the Frequency of CD4+foxp3+ICOS- Regulatory T Cells
</title>
<snippet>
Mesothelin Virus-Like Particle Immunization Controls Pancreatic Cancer Growth through CD8+ T Cell Induction and Reduction in the Frequency of CD4+foxp3+ICOS- Regulatory T Cells
</snippet>
<url>http://dx.doi.org/10.1371/journal.pone.0068303</url>
</document>
</searchresult>
I need to output from the XSL a static CDATA construct embedded in the XSL, not from the XML that I am transforming. For example...
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="xml" indent="yes"/>
<!-- ================================================== -->
<xsl:template match="/">
<Document>
<text><![CDATA[
<b>static</b>
<br/><br/>
text
<br/><br/>
]]>
</text>
<xsl:apply-templates select="//tag"/>
</Document>
</xsl:template>
<!-- ================================================== -->
<xsl:template match="tag">
So on and so forth...
</xsl:template>
<!-- ================================================== -->
</xsl:stylesheet>
I want this to output...
<?xml version="1.0"?>
<Document>
<text><![CDATA[
<b>static</b>
<br/><br/>
text
<br/><br/>
]]>
</text>
So on and so forth...
</Document>
But what I get is...
<?xml version="1.0"?>
<Document>
<text>
<b>static</b>
<br/><br/>
text
<br/><br/>
</text>
So on and so forth...
</Document>
I've tried several combinations of escaping the text and entities, but none seem to work.
Use
<xsl:output cdata-section-elements="text" />
to enforce CDATA for certain elements (spec).
In any case, what you currently get is equivalent to a CDATA section and it should not bother you. (i.e.: If it's bothering you for optical reasons, then get over it. If it is bothering you for technical reasons, fix them.)
I'm currently stuck trying to use XSL to transform a XML document into HTML. The XML document uses namespaces and I don't really have too much experience with XSL let alone namespaces. Basically all I want to do is grab every instance of s:treatment and output this as a list. I've changed data so not to expose the website I'm doing this for. I'm using Classic ASP (can't update to ASP.NET) to transform the XML on the server, so the XSL has to be version 1 :(
Any help would be really appreciated here as I just can't figure out what's going wrong.
Here's the XML:
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">a</title>
<id>a</id>
<rights type="text">© Crown Copyright 2009</rights>
<updated>2011-01-19T11:23:25Z</updated>
<category term="Service"/>
<author>
<name>c</name>
<uri>http://www.meh.com</uri>
<email>erwt</email>
</author>
<complete xmlns="http://purl.org/syndication/history/1.0"/>
<entry>
<id>http://meh.com/services</id>
<title type="text">title</title>
<updated>2010-06-18T19:52:12+01:00</updated>
<link rel="self" title="title" href="meh"/>
<link rel="alternate" title="title" href="id"/>
<content type="application/xml">
<s:service xmlns:s="http://syndication.nhschoices.nhs.uk/services">
<s:type code="S">h</s:type>
<s:deliverer>j</s:deliverer>
<s:parent>k</s:parent>
<s:treatments>
<s:treatment>fissure</s:treatment>
<s:treatment>fistula</s:treatment>
<s:treatment>liver</s:treatment>
<s:treatment>pancreas</s:treatment>
<s:treatment>Cirrhosis</s:treatment>
<s:treatment>Coeliac disease</s:treatment>
<s:treatment>Crohn's disease</s:treatment>
<s:treatment>Diagnostic endoscopy of the stomach</s:treatment>
<s:treatment>Diverticular problems</s:treatment>
<s:treatment>Gastrectomy</s:treatment>
<s:treatment>Gastroenteritis</s:treatment>
<s:treatment>Gastroenterology</s:treatment>
<s:treatment>Gastroesophageal reflux disease(GORD)</s:treatment>
<s:treatment>Hepatitis</s:treatment>
<s:treatment>Hepatitis A</s:treatment>
<s:treatment>Hepatitis B</s:treatment>
<s:treatment>Hepatitis C</s:treatment>
<s:treatment>Hernia hiatus</s:treatment>
<s:treatment>Ileostomy</s:treatment>
<s:treatment>Irritable bowel syndrome</s:treatment>
<s:treatment>Liver disease (alcoholic)</s:treatment>
<s:treatment>Obesity</s:treatment>
<s:treatment>Pancreatitis</s:treatment>
<s:treatment>Peptic ulcer</s:treatment>
<s:treatment>Peritonitis</s:treatment>
<s:treatment>Primary biliary cirrhosis</s:treatment>
<s:treatment>Surgery for haemorrhoids</s:treatment>
<s:treatment>Therapeutic endoscopy on the stomach</s:treatment>
<s:treatment>Ulcerative colitis</s:treatment>
</s:treatments>
<s:phone>020 8</s:phone>
<s:fax>020 8</s:fax>
<s:email>jj</s:email>
<s:website>oiyi</s:website>
</s:service>
</content>
</entry>
</feed>
As you can see it uses the Atom namespace, Purl syndication namespace and NHS Choices namespace only the NHS Choices namespace actually uses the prefix though, this is what is confusing me really. How would I declare the other namespaces and do I even need to?
Here's my XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="http://syndication.nhschoices.nhs.uk/services">
<ul>
<xsl:template match="/">
<xsl:for-each select="feed/entry/content/s:service/s:treatments/s:treatment">
<li><xsl:text></xsl:text></li>
</xsl:for-each>
</xsl:template>
</ul>
</xsl:stylesheet>
This XSL was taken from the w3schools example so apologies if it's bare.
Any ideas what I need to do to make this work?
Thanks,
Colin
First of all your XSLT is not valid at all (uloutside xsl:template is not valid XSL).
Further more as there is a default namespace on your feed tag you have also to define this in your xslt. You also better make usage of mathcing templates intead of for-each loops in CSLT.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:s="http://syndication.nhschoices.nhs.uk/services"
xmlns:a="http://www.w3.org/2005/Atom" exclude-result-prefixes="a s">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<ul>
<xsl:apply-templates
select="a:feed/a:entry/a:content/s:service/s:treatments/s:treatment" />
</ul>
</xsl:template>
<xsl:template match="s:treatment">
<li>
<xsl:value-of select="." />
</li>
</xsl:template>
</xsl:stylesheet>
I've got a problem with xsl:include and default namespaces which is causing the final xml document contain nodes with the xmlns=""
In this synario I have 1 source document which is Plain Old XML and doesn't have a namespace:
<?xml version="1.0" encoding="UTF-8"?>
<SourceDoc>
<Description>Hello I'm the source description</Description>
<Description>Hello I'm the source description 2</Description>
<Description/>
<Title>Hello I'm the title</Title>
</SourceDoc>
This document is transformed into 2 different xml documents each with their own default namespace.
First Document:
<?xml version="1.0" encoding="utf-8"?>
<OutputDocType1 xmlns="http://MadeupNS1">
<Description >Hello I'm the source description</Description>
<Description>Hello I'm the source description 2</Description>
<Title>Hello I'm the title</Title>
</OutputDocType1>
Second Document:
<?xml version="1.0" encoding="utf-8"?>
<OutputDocType2 xmlns="http://MadeupNS2">
<Description>Hello I'm the source description</Description>
<Description>Hello I'm the source description 2</Description>
<DocTitle>Hello I'm the title</DocTitle>
</OutputDocType2>
I want to be able to re-use the template for descriptions in both of the transforms. As it's the same logic for both types of document. To do this I created a template file which was xsl:included in the other 2 transformations:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="Description[. != '']">
<Description>
<xsl:value-of select="."/>
</Description>
</xsl:template>
</xsl:stylesheet>
Now the problem here is that this shared transformation can't have a default Namespace as it will be different depending on which of the calling transformations calls it.
E.g. for First Document Transformation:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="SourceDoc">
<OutputDocType1 xmlns="http://MadeupNS1">
<xsl:apply-templates select="Description"/>
<xsl:if test="Title">
<Title>
<xsl:value-of select="Title"/>
</Title>
</xsl:if>
</OutputDocType1>
</xsl:template>
<xsl:include href="Template.xsl"/>
</xsl:stylesheet>
This actually outputs it as follows:
<?xml version="1.0" encoding="utf-8"?>
<OutputDocType1 xmlns="http://MadeupNS1">
<Description xmlns="">Hello I'm the source description</Description>
<Description xmlns="">Hello I'm the source description 2</Description>
<Title>Hello I'm the title</Title>
</OutputDocType1>
Here is the problem. On the description Lines I get an xmlns=""
Does anyone know how to solve this issue?
Thanks
Dave
Your first xslt, which contains the literal result element Description has no default namespace. This element is therefore in no namespace, and is being explicitly rendered as such via xmlns="".
Section 6.2 of Namespaces in XML 1.0 says that:
The attribute value in a default
namespace declaration MAY be empty.
This has the same effect, within the
scope of the declaration, of there
being no default namespace.
In order to control the namespace generated in the included stylesheet you will need to pass the namespace-uri through to its templates, using a variable or param.
<!-- in the included stylesheet -->
<xsl:template match="Description[. != '']">
<xsl:element name="Description" namespace="{$output-namespace}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<!--
and add this to your First Document Transformation stylesheet
as a top level element under xsl:stylesheet
-->
<xsl:variable name="output-namespace" select="'http://MadeupNS1'"/>