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

Subject: RE: [xsl] Stumped on why a field isn't showing up
From: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Sun, 13 Jun 2004 06:19:10 -0600
Hello Deirdre,

The first thing I notice in your stylesheet is the fact that you are
selecting "novel/chapter" for your first apply-templates.  According to
your sample XML there is no novel/chapter.  There is a text node
"&ch01;" that looks like it could at one point been a representation of
something but I'm just making a guess.  

This is where your problem begins.  If leaving out the chapter element
was intended that would explain why it isn?t there.  But even as such
your second template has several other problems.  

First...

It is using "chapter" as the context of continuing the recursion process
of apply-templates.  Since "author" and "address" are child elements of
"novel" and not "chapter" the apply-templates process being invoked
doesn?t find any child elements following the chapter path and stop's
the processing for that element.

There are two ways to fix this:

1) Add a root ("/") reference to the beginning of your apply-templates
for the "author" and "address". So, turn this:

<xsl:apply-templates select="novel/author"/>
<xsl:apply-templates select="novel/address"/>

Into this:

<xsl:apply-templates select="/novel/author"/>
<xsl:apply-templates select="/novel/address"/>

The problem with this approach is that you are causing your processor to
work overtime trying to access the nodes you are in desire of.  In
theory you are saying:

Take the element "chapter" (and all of its children) that is a child of
"novel" and find a template that has matches its name.

Once you have matched and processed it go back to the root and then find
/novel/author and process that.

When you're done with that go back to the root again and find
/novel/address and process that.  

Its like having a grocery list with three(3) items on it: milk, sugar,
and eggs;  Instead of getting all of them at one time you get the milk
and take it home.  You then go back and get the sugar... and go home.
And since your list still has one more item its back to the store to
pick up some eggs.  Efficiency in daily life is crucial - as is the
methods we use in software development if performance is of any
consideration (and it ALWAYS should be.)

The one other thing I should point out is the fact that you have an
extra </xsl:apply-templates> in your second template.  If you were able
to get this stylesheet to run at all then this couldn?t have been there
otherwise the parser would have thrown a red flag and stopped the
processing before it even had begun.  None the less, you should be aware
of two things:

1) Your XSLT must be well formed XML.  If its not, it will not work.
2) You cannot nest apply-templates.  I don?t know for sure if the reason
that extra </xsl:apply-templates> was there because at one point it
contained a matching start element (the two xsl:apply-templates are
already closed using the short hand method for ending and element tag -
e.g. "<tag/>" instead of "<tag>content of tag</tag>".  If it did, your
processor should have noticed it and said no.  If it didn?t then its
time to use a new processor.  And if I'm just seeing something that
really isn?t and issue because of a simple copy and paste error then
please disregard :)

I hope this helps you get a little closer to where you want to be!  And
don?t hesitate to ask further questions if the need arises.

Best of luck!

<M:D/>





-----Original Message-----
From: Deirdre Saoirse Moen [mailto:deirdre@xxxxxxxxxxx] 
Sent: Sunday, June 13, 2004 5:18 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Stumped on why a field isn't showing up

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.

What I don't understand (and I've tried several approaches including 
putting it in several places) why the name and address fields *don't* 
render. Code is below. Output can be seen at 
http://deirdre.org/df-synopsis-1.pdf

Here's my understanding of what it's doing:

1) the page master is telling it to render novel/chapter
2) chapter is rendering the heading, omitting the name and address in 
the body
3) it then renders the rest of the tags, including the chapter heading 
(in this case, synopsis) and the chapter body.

Incoming XML file:
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE novel SYSTEM 'prose.dtd'
   [
      <!ENTITY ch01 SYSTEM "df-synopsis-1.xml">
   ] >
   <novel>
     <title>Deep Fried</title>
     <author>Deirdre Saoirse Moen</author>
     <address>2033 Sharon Road</address>
     <address>Menlo Park, CA 94025</address>
     <address>650-561-9820 (H)</address>
     <address>650-283-6636 (M)</address>
     <address>deirdre@xxxxxxxxxxx</address>
     <wordcount>Approx. 100,000 words</wordcount>
     <heading>Saoirse Moen / Synopsis: Deep Fried</heading>
     &ch01;
   </novel>


XSL file:

<?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'>

<xsl:output method='xml'/>

<!-- Show comments in the prose as footnotes -->
<xsl:template match="/">
   <fo:root font-family="Courier" font-size="12pt">
     <fo:layout-master-set>
       <fo:simple-page-master master-name="manuscript-body">
         <fo:region-before extent="1.5in"/>
         <fo:region-body margin-left="1in" margin-right="1in"
         		 margin-top="1.5in" margin-bottom="1in"/>
       </fo:simple-page-master>
     </fo:layout-master-set>
     <xsl:apply-templates select="novel/chapter"/>
   </fo:root>
</xsl: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/>
       </fo:block>
     </fo:static-content>
     <fo:flow flow-name="xsl-region-body" line-height="1.5">
       <xsl:apply-templates select="novel/author"/>
		<xsl:apply-templates select="novel/address"/>
       <xsl:apply-templates/>
     </fo:flow>
   </fo:page-sequence>
</xsl:template>



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

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

<xsl:template match="chapter/title">
<xsl:choose>
   <xsl:when test="../subtitle">
   <fo:block font-weight="bold" text-align="center"
space-after="0.25in">
     <xsl:value-of select="../title"/>
   </fo:block>
   </xsl:when>
   <xsl:otherwise>
   <fo:block font-weight="bold" text-align="center"
space-after="0.25in">
     <xsl:value-of select="."/>
   </fo:block>
   </xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="chapter/subtitle">
   <fo:block font-weight="bold" text-align="center"
 
space-after="0.25in">
     <xsl:value-of select="."/>
   </fo:block>
</xsl:template>

<xsl:template match="par">
   <fo:block text-indent="0.5in">
   <xsl:if test="number(@indent) &gt; 0">
     <xsl:attribute name="start-indent">
       <xsl:value-of select="concat(@indent*0.5,'in')"/>
     </xsl:attribute>
     <xsl:attribute name="end-indent">
       <xsl:value-of select="concat(@indent*0.5,'in')"/>
     </xsl:attribute>
   </xsl:if>
   <xsl:apply-templates/>
   </fo:block>
</xsl:template>

<xsl:template match="emph[@style='standard'] | 
emph[@style='underline']">
   <fo:inline text-decoration="underline">
     <xsl:apply-templates/>
   </fo:inline>
</xsl:template>

<xsl:template match="emph[@style='italic']">
   <fo:inline font-style="italic">
     <xsl:apply-templates/>
   </fo:inline>
</xsl:template>

<xsl:template match="emph[@style='bold']">
   <fo:inline font-weight="bold">
     <xsl:apply-templates/>
   </fo:inline>
</xsl:template>

<xsl:template match="secbreak">
   <fo:block text-align="center">#</fo:block>
</xsl:template>

</xsl:stylesheet>

-- 
_Deirdre                                             http://deirdre.net
"Cannot run out of time. There is infinite time. You are finite. 
Zathras is finite. This....is wrong tool."  -- Zathras


--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
--+--


Current Thread