I have hundreds of lines of text, being formatted in an XML doc that I need to output to a PDF and display as:
LEFT TEXT.......................................................................RIGHT TEXT
I discovered how to do this in the XSL, but it is currently running as a processing instruction, during FO output. XSL:
<xsl:template match="processing-instruction('leftrighttext')">
<fo:block text-align-last="justify">
<xsl:text>LEFT TEXT</xsl:text>
<fo:leader leader-pattern="dots"/>
<xsl:text>RIGHT TEXT</xsl:text>
</fo:block>
What the XML looks like (being used in a table):
<row>
<entry> <?leftrighttext?> </entry>
</row
Desired Output:
LEFT TEXT........................................................................RIGHT TEXT
NEXT TEXT WITHIN TABLE...........................................................OTHER TEXT
My question is how would I get the "LEFT TEXT" and "RIGHT TEXT" to be called from the XML document, instead of inputting the values directly in the stylesheet, such as:
<row>
<entry>LEFT TEXT <sometag> RIGHT TEXT</entry>
</row>
<row>
<entry>NEXT TEXT WITHIN TABLE <sometag> OTHER TEXT
Is there a tag I can create, or a string to identify the text before a tag, and the text after, input dot leaders between them?
Any help would be appreciated.
Additional Information Requested: I used the XSLT posted in the answer below, here is the XML doc I am trying to transform. I also followed the outline for the XML that wsas posted below. Please let me know what I'm missing...
XML:
<?xml-model href="http://docbook.org/xml/5.0/rng/docbook.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://docbook.org/xml/5.0/rng/docbook.rng" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
version="5.0">
<table>
<tgroup cols="2">
<colspec colnum="1" colname="col1" colwidth="235"/>
<colspec colnum="2" colname="col2" colwidth="235"/>
<thead>
<row>
<entry align="center">LSP</entry>
<entry align="center">RSP</entry>
</row>
</thead>
<tbody>
<row>
<entry align="center" namest="col1" nameend="col2">(PF) Takeoff Briefing<?leftrighttext?>PERFORM</entry>
</row>
</tbody>
</tgroup>
</table>
</section>
This is what I have for the beginning of the stylesheet:
XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:d="http://docbook.org/ns/docbook"
exclude-result-prefixes="xs date"
extension-element-prefixes="date"
version="1.0">
<xsl:import href="http://docbook.sourceforge.net/release/xsl-ns/current/fo/docbook.xsl"/>
I would stick with your original approach of using a processing instruction. You just need to use
xsl:apply-templates
to build up thefo:table-cell
.Example:
XML Input
XSLT 1.0
XSL-FO Output
Rendered PDF
UPDATED EXAMPLE
Looking at your update XML example I see that you have a default namespace (
xmlns="http://docbook.org/ns/docbook"
). What you should do is declare that namespace with a prefix in your XSLT and then use that prefix in your XPaths.If you're using XSLT 2.0, you could instead add
xpath-default-namespace="http://docbook.org/ns/docbook"
to yourxsl:stylesheet
and not change any of your XPaths.It's hard to recommend something specific because you haven't shown a complete XSLT (or even a template that shows us the context of where the tbody is being created), so this is a complete guess.
Here's an example using your updated XML and declaring the
http://docbook.org/ns/docbook
namespace with the prefixdoc
.(I didn't try to handle the table headers or anything like that just to keep it simple.)
XML Input
XSLT 1.0
XSL-FO Output
Rendered PDF