Re: [xsl] Stumped on why a field isn't showing up

Subject: Re: [xsl] Stumped on why a field isn't showing up
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Sun, 13 Jun 2004 13:50:00 +0200
Deirdre Saoirse Moen wrote:
I'm trying to learn XSL(-FO), so I'm still beating my head against the wall.

I've managed to get everything except, oh, the most important piece of information to render correctly.

It seems you are missing some important concepts, in particular the concept of the context node in an XSLT template:

<xsl:template match="/">
  <fo:root font-family="Courier" font-size="12pt">
...
<xsl:apply-templates select="novel/chapter"/>

At this point the context node is the tree's root node. You are telling the processor to get the node set containing the novel/chapter nodes and apply templates, which will hopefully be matched by the following template:

<xsl:template match="chapter">
  <fo:page-sequence master-reference="manuscript-body">
    <fo:static-content flow-name="xsl-region-before">
      <fo:block text-align="right" space-before="1in" end-indent="1.5in">
        <xsl:value-of select="/novel/heading"/> / <fo:page-number/>
Here you use an absolute XPath, which will get you the
string value of /novel/heading, something you probably expect.

    <fo:flow flow-name="xsl-region-body" line-height="1.5">
      <xsl:apply-templates select="novel/author"/>
However, at this point you use a relative XPath (no slash "/"
in format). This means the processor will try to walk it down
from the context node, which is most likely a /novel/chapter
node. I suppose these nodes don't have a novel child, and you
wont get to the /novel/author node anyway.
You want to use
       <xsl:apply-templates select="/novel/author"/>
       <xsl:apply-templates select="/novel/address"/>
here.

You should probably think about restructuring your processing
logic. In many cases it's considered "bad style" to grab parts
outside the subtree starting at the currently processed node.
A way to avoid this is to use template parameters, they have
their own set of drawbacks though.

J.Pietschmann

Current Thread