[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Inlining blocks in FO


Subject: Re: [xsl] Inlining blocks in FO
From: "Mark Wilson" <mark@xxxxxxxxxxxx>
Date: Sat, 7 Mar 2009 08:30:06 -0700

Hi Ken,
Right on the mark!
Thanks.

Mark

--------------------------------------------------
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Sent: Saturday, March 07, 2009 8:17 AM
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: [xsl] Inlining blocks in FO

At 2009-03-07 07:55 -0700, Mark Wilson wrote:
I am trying to produce a PDF document formatted like:

Adobovs, Kivdul
Letters to the editor. Nov/Dec 2001 p.27 .
Philatelic news and views. Sep/Oct 2001 p.35; Sep/Oct 2002 p.11; Nov/Dec 2002 p.28; Jan/Feb 2003 p.24 .


My template file gives me:

Adobovs, Kivdul
Letters to the editor. Nov/Dec 2001 p.27 .
Philatelic news and views. Sep/Oct 2001 p.35 ;
Sep/Oct 2002 p.11 ;
Nov/Dec 2002 p.28 ;
Jan/Feb 2003 p.24 .

Can someone help me understand how to get the citation elements from articles with the same <Title> all on the same line? I think I need to process the entire node-set for "Philatelic news and views" simultaneously, but am not sure how to write that template.

By thinking about grouping. You've taken a number of tangents working with axes that are not at all necessary. Things come together so much easier when using grouping, and I find my students get hung up on axes without taking a look at the bigger picture.


But you said it correctly: "I need to process the entire node-set for "Philatelic news and views" simultaneously".

And that you are using XSLT 2.0 makes that so much easier than XSLT 1.0.

My XSLT and XML files, much abbreviated but still functional, follow.

Thank you! That made it easier to hack a more appropriate solution.


I also note you are using empty <fo:wrapper> elements in your XSL-FO ... empty wrapper elements not helpful in any way, so I've removed them.

Finally, you need to remember the availability of position() and last() functions when dealing with the current node list ... adding the semi-colon separator and period terminator are a lot easier with these than when trying to deal with axes. You'll note below I never look at a preceding or following axis ... it isn't very often when one has to do so.

I hope the code below helps.

. . . . . . . . . . Ken

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
<xsl:template match="/">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="page">
<fo:region-body region-name="body" margin-top="0.5in" margin-bottom="1in" margin-left="0.5in" margin-right="0.5in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="page">
<fo:flow flow-name="body">
<xsl:apply-templates/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>


   <!--take a look at all articles in the item-->
   <xsl:template match="Item">
     <!--first get the heading out of the way-->
     <xsl:apply-templates select="Heading"/>
     <!--now group the articles-->
     <xsl:for-each-group select="Article" group-by="Title">
       <!--and put all citations in one block-->
       <fo:block>
         <!--for a given title-->
         <xsl:apply-templates select="Title"/>
         <xsl:text>: </xsl:text>
         <!--and for each citation-->
         <xsl:apply-templates select="current-group()"/>
       </fo:block>
     </xsl:for-each-group>
   </xsl:template>

   <!--format the item's heading-->
   <xsl:template match="Heading">
       <fo:block>
           <xsl:apply-templates/>
       </fo:block>
   </xsl:template>

   <!--format a citation-->
   <xsl:template match="Article">
     <xsl:value-of select="IssueName,Year"/>
     <xsl:text/> p.<xsl:value-of select=" Page"/>
     <xsl:choose>
       <xsl:when test="position()=last()">.</xsl:when>
       <xsl:otherwise>; </xsl:otherwise>
     </xsl:choose>
   </xsl:template>

</xsl:stylesheet>


-- XQuery/XSLT training in Prague, CZ 2009-03 http://www.xmlprague.cz XQuery/XSLT/XSL-FO training in Los Angeles/Anaheim - 2009-06-01/10 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal


Current Thread
Keywords