Re: [xsl] XSL:FO Identify Transforms

Subject: Re: [xsl] XSL:FO Identify Transforms
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 16 Sep 2011 12:33:01 -0400
At 2011-09-16 17:19 +0100, you wrote:
I have an XSL I use for identifying the XML - e.g. takes the XML and transforms it into another XML. This works as expected when it's XSLT.
However I need to make this work in the same work but using XSL:FO so that it can be made pretty for print and outputted as a PDF.


I am sure this should be simple, and I am missing something obvious.

A user's vocabulary cannot simply be copied into an XSL-FO file, just in the same way it cannot simply be copied into an HTML file.


How can I get the <xsl:copy> and <xsl:elements> working in FO, or something similar?

By not using those instructions and translating your input into appropriate XSL-FO constructs.


For example, match on your block-level constructs and use <fo:block>, and match on your inline-level constructs and use <fo:inline>.

<xsl:template match="/ | node()">
                <xsl:copy>
                   <xsl:apply-templates select="@* | node()" />
                </xsl:copy>
</xsl:template>

Above you are copying your input


<xsl:template match="@*" >
<xsl:element name="attribute">
<xsl:attribute name="name">
<xsl:value-of select="local-name()" />
</xsl:attribute>
<xsl:value-of select="." />
</xsl:element>
</xsl:template>

Unrelated to your question, the above can be replaced with:


<xsl:template match="@*"><xsl:copy/></xsl:template>

.... or even incorporated into a single template rule with:

<xsl:template match="node() | @*">
                <xsl:copy>
                   <xsl:apply-templates select="@* | node()" />
                </xsl:copy>
</xsl:template>

... but it is still inappropriate in your stylesheet to go to XSL-FO.

SAMPLE XML:
<?xml version="1.0" encoding="UTF-8"?>
<xml>
            <header>
                        <test>This is  test</test>
            </header>
</xml>

The XSL-FO specification tells an engine to tolerate elements it does not recognize when those elements are not in the XSL-FO namespace, but it throws them and their content away.


The HTML specification tells a browser to tolerate elements it does not recognize, but it still processes the content of that unrecognized element.

Again, draw the parallel to HTML: if you used the identity transform in a stylesheet going to HTML, your end result would have <header> and <test> elements in the HTML and you wouldn't get a pretty print because a browser does not recognize your vocabulary. In HTML you have to build a document of <div> and <span> (or whatever HTML) from your XML.

Similarly, when using XSL-FO you have to build a document of <block> and <inline> (or whatever XSL-FO) from your XML, because the engine does not recognize your vocabulary.

I hope this helps.

. . . . . . . . . . . Ken


-- Contact us for world-wide XML consulting and instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread