Re: [xsl] I'm obviously doing something wrong

Subject: Re: [xsl] I'm obviously doing something wrong
From: JBryant@xxxxxxxxx
Date: Wed, 27 Apr 2005 14:59:25 -0500
This sample has a number of issues:

First, you have a data issue: Regardless of indentation, the Topic and 
Panel elements are siblings. <xsl:apply-templates select="Panel"/>  within 
the Topic template does nothing because no Topic node has Panel children. 
Thus, you have a grouping problem.

You also have an FO problem: In your simple-page-master, you specify 
regions but don't provide names.

<fo:region-body margin-left="2in" margin-right="1in" margin-top="1in" 
margin-bottom="1.5in"/>
needs to be
<fo:region-body region-name="xsl-region-body" margin-left="2in" 
margin-right="1in" margin-top="1in" margin-bottom="1.5in"/>

and so on for the other regions (region-after in your case).

Consequently, the regions will never be inserted into the document, 
resulting in an empty document. I'd also be surprised if you didn't get 
multiple error messages from your processor. I suppose you're not getting 
to these errors because the FO processor doesn't recognize the Topics 
node. As David Carlisle pointed out, you need to transform with XSLT to 
get an FO document and then use an FO processor construct your result 
document (PDF, I suppose) from the FO document.

I have no idea what tools are in the Oxygen system, so I can't give more 
specific advice. However, the general process should be the same 
regardless of tools:
XML source + XSLT stylesheet + XSLT processor => XSL-FO document
XSL-FO document + XSL-FO processor => result document

HTH

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)





Deirdre Saoirse Moen <deirdre@xxxxxxxxxxx> 
04/27/2005 02:32 PM
Please respond to
xsl-list@xxxxxxxxxxxxxxxxxxxxxx


To
<xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
cc

Subject
[xsl] I'm obviously doing something wrong






I've stared at it and fiddled with it, and another person's looked at it
and can't figure it out either.

I'm getting the dreaded "Root element must be root, not Topics," but I
can't quite grok why (yes, I've looked at every example Google came up
with; the reasons given either didn't seem to apply or weren't helpful).
In general, the explanations given were so terse that I'd only understand
them if I already understood what I did wrong, thus creating a bootstrap
issue for people trying to learn.

Naturally, I cobbled parts of this together from working stylesheets.

In case it is an issue, I'm using the toolchain embedded in oXygen 5.1.

Can someone point out what I'm doing wrong?

XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="mTopicsPanels.xsl"?>
<!DOCTYPE
Topics [

<!ELEMENT Topics ANY>
<!ELEMENT Topic ANY>
<!ELEMENT Panel ANY>

]>
<Topics>
                 <Topic>A</Topic>
                                 <Panel>First</Panel>
                                 <Panel>Second</Panel>
                                 <Panel>Third</Panel>
                                 <Panel>Fourth</Panel>
                 <Topic>B</Topic>
                                 <Panel>First</Panel>
                                 <Panel>Second</Panel>
                                 <Panel>Third</Panel>
                                 <Panel>Fourth</Panel>
</Topics>

XSL:

<?xml version='1.0'?>

<xsl:stylesheet version='1.0'
                 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
                 xmlns:fo='http://www.w3.org/1999/XSL/Format'
                 xmlns:fox='http://xml.apache.org/fop/extensions'
                 xmlns:date='java.util.Date'
                 xmlns:format='java.text.SimpleDateFormat'
exclude-result-prefixes='date'>

<xsl:output method='xml'/>

<xsl:template match="/">
  <fo:root font-family="Helvetica" font-size="12pt"
xmlns:fo="http://www.w3.org/XSL/Format/1.0";>
    <fo:layout-master-set>

      <fo:simple-page-master master-name="contents">
        <fo:region-body margin-left="2in" margin-right="1in"
                                          margin-top="1in" 
margin-bottom="1.5in"/>
        <fo:region-after extent="1in"/>
     </fo:simple-page-master>
    </fo:layout-master-set>

<!-- image the pages -->

                 <fo:page-sequence master-reference="contents"
initial-page-number="1">
    <fo:static-content flow-name="xsl-region-after">
                 <fo:block text-align="left" space-after="0.75in" 
font-size="8pt">
                                 <fo:page-number/>
        </fo:block>
      <fo:block text-align="right" space-after="0.75in" end-indent="1.0in"
font-size="8pt">
                                                 <xsl:variable
name="pattern">yyyy-MM-dd</xsl:variable>
                                                 <xsl:variable 
name="SimpleDateFormat"
select="format:new($pattern)"/>
                                                 <xsl:variable name="Date" 
select="date:new()"/>
                                                 As of: <xsl:value-of
select="format:format($SimpleDateFormat, $Date)"/>
      </fo:block>
    </fo:static-content>

                   <fo:flow flow-name="xsl-region-body">
                     <xsl:apply-templates />
                   </fo:flow>
                 </fo:page-sequence>
  </fo:root>
</xsl:template>

 <xsl:template match="Topic">
    <fo:block font-weight="bold" text-align="center" space-before="12pt">
        <xsl:value-of select="."/>
    </fo:block>
    <xsl:apply-templates select="Panel"/>
</xsl:template>

<xsl:template match="Panel">
  <fo:block text-align="left">
    <xsl:value-of select="."/>
  </fo:block>
</xsl:template>

</xsl:stylesheet>


-- 
_Deirdre  web: http://deirdre.net        blog: http://deirdre.org/blog/
yarn: http://fuzzyorange.com    cat's blog: http://fuzzyorange.com/vsd/
"Memes are a hoax! Pass it on!"

Current Thread