Re: [xsl] how to translate XML with XHTML-formatted element to FO

Subject: Re: [xsl] how to translate XML with XHTML-formatted element to FO
From: Alex Milowski <alexml@xxxxxxxxxxxx>
Date: Tue, 12 Apr 2005 18:14:30 -0700
On Apr 12, 2005, at 11:12 AM, Magic Finger wrote:

how can I translate XML files (like the following), which contain
XHTML-formatted text in one element, to PDF using Apache FOP ?

 --- books.xml --->
 <BOOK>
   <AUTHOR>Walt Disney</AUTHOR>
   <PRICE>19.90</PRICE>
   <TITLE>&lt;b&gt;Donald Duck - &lt;i&gt;The True Story&lt;/i&gt;
&lt;/b&gt;</TITLE>
 </BOOK>

 <BOOK>
   <AUTHOR>Matt Groening</AUTHOR>
   <PRICE>25.00</PRICE>
   <TITLE>&lt;b&gt;Homer Simpson For President&lt;/b&gt;</TITLE>
 </BOOK>
   ...
 <--- books.xml ---

You can translate the escape XHTML with a XML pipeline as implemented by the smallx [1] project at java.net:

<p:pipe name="xhtml-convert"
   xmlns:p="urn:publicid:IDN+smallx.com:pipeline:1.0";
>

<p:subtree select="TITLE">
<p:parse/>
</p:subtree>

</p:pipe>

That will convert:

<TITLE>&lt;b&gt;Homer Simpson For President&lt;/b&gt;</TITLE>

to:

<TITLE><b xmlns="http://www.w3.org/1999/xhtml";>Homer Simpson For President</b></TITLE>

You can also "trap" parse errors:

<p:pipe name="xhtml-convert"
   xmlns:p="urn:publicid:IDN+smallx.com:pipeline:1.0";
>

<p:subtree select="TITLE">

<p:trap>

<p:parse/>

<p:on-error>
<p:template>
<TITLE bad="true"><xsl:copy-of select="/*/node()"/></TITLE>
</p:template>
</p:on-error>

</p:trap>

</p:subtree>

</p:pipe>

[1] http://smallx.dev.java.net

-- Alex Milowski

"The excellence of grammar as a guide is proportional to the paucity of the
inflexions, i.e. to the degree of analysis effected by the language
considered."


Bertrand Russell in a footnote of Principles of Mathematics

Current Thread