That highlights very closely to what I have done; although I like the
elegance the author has used.  That is the next task is to clean up my
XSLT file so that it is much easier to read.

 

From: Lloyd Cotten [mailto:ll...@lloydcotten.com] 
Sent: Friday, September 10, 2010 10:50 AM
To: fop-users@xmlgraphics.apache.org
Subject: Re: XSLT Help

 

Hi Chris,

I was attempting to do something similar in the past week, and came
across the following discussion on the issue.  I found it helpful:

http://nick-dunn.co.uk/article/an-alternative-for-loop-using-xslt-and-te
mplate-callbacks/

Lloyd

On Fri, Sep 10, 2010 at 12:53 PM, CRANFORD, CHRIS
<chris.cranf...@setech.com> wrote:

Not necessarily write it for me, just direction.  I have been playing
with recursive template calls all morning, and thus far this is what
I have arrived at is the following:

<!--
 This template matches against a planning record
 entry in the plan for every part XML document.
-->
<xsl:template match="record">
 <xsl:call-template name="forLoopYear">
   <xsl:with-param name="start">
     <xsl:value-of select="$curYear"/>
   </xsl:with-param>
   <xsl:with-param name="end">
     <xsl:value-of select="$curYear+(-4)"/>
   </xsl:with-param>
 </xsl:call-template>
</xsl:template>

<!--
 This template handles iterating over a start
 and end year values stepping by 1 year.
-->
<xsl:template name="forLoopYear">
 <xsl:param name="start"/>
 <xsl:param name="end" />

 <xsl:if test="$start != $end">

   <xsl:value-of select="$start"/><xsl:text> </xsl:text>

   <xsl:call-template name="forLoopMonth">
     <xsl:with-param name="month">1</xsl:with-param>
     <xsl:with-param name="year">
       <xsl:value-of select="$start"/>
     </xsl:with-param>
   </xsl:call-template>

   <xsl:call-template name="forLoopYear">
     <xsl:with-param name="start">
       <xsl:value-of select="$start+1"/>
     </xsl:with-param>
     <xsl:with-param name="end">
       <xsl:value-of select="$end"/>
     </xsl:with-param>
   </xsl:call-template>

 </xsl:if>
</xsl:template>

<!--
 This template handles iterating over months 1
 Through 12, looks up the data from the XML
 Document and if it exists, displays it;
 Otherwise outputs a 0 for the month/year.
-->
<xsl:template name="forLoopMonth">
 <xsl:param name="month"/>
 <xsl:param name="year"/>

 <xsl:if test="$month &lt;= 12">
   <xsl:for-each select="usage/details/detail">
     <xsl:if test="year = $year">
       <xsl:if test="month = $month">
         <xsl:value-of select="quantity"/><xsl:text> </xsl:text>
       </xsl:if>
     </xsl:if>
   </xsl:for-each>

   <xsl:call-template name="forLoopMonth">
     <xsl:with-param name="month">
       <xsl:value-of select="$month+1"/>
     </xsl:with-param>
     <xsl:with-param name="year">
       <xsl:value-of select="$year"/>
     </xsl:with-param>
   </xsl:call-template>

 </xsl:if>

</xsl:template>

First, this a good approach or is there a better way?

Secondly, how do I handle the scenario where I do not find the node
/usage/details/detail with the specified year/month to output a
standard 0 value?

And I need to look at the original link on how to handle the sum
logic that I will need with this.


> -----Original Message-----
> From: Eric Douglas [mailto:edoug...@blockhouse.com]

> Sent: Friday, September 10, 2010 9:48 AM
> To: fop-users@xmlgraphics.apache.org
> Subject: RE: XSLT Help
>
> I was just confused then where you said your "XSLT starts with
> 2010...".
> You apparently meant to say your XSLT does nothing, but this is what
it
> needs to do.
> Are you looking for someone to write an entire XSL file for you, or
> what
> part are you struggling with?
>
> -----Original Message-----
> From: CRANFORD, CHRIS [mailto:chris.cranf...@setech.com]
> Sent: Friday, September 10, 2010 10:42 AM
> To: fop-users@xmlgraphics.apache.org
> Subject: RE: XSLT Help
>
> No, all I was showing was the expected output.  I still need to code
> the
> XSLT to actually generate that.
>
> > -----Original Message-----
> > From: Eric Douglas [mailto:edoug...@blockhouse.com]
> > Sent: Friday, September 10, 2010 9:33 AM
> > To: fop-users@xmlgraphics.apache.org
> > Subject: RE: XSLT Help
> >
> > You already have the XSL to print the months and years and all you
> need
> > is the method to add up the data fields?
> > It sounds like you have the hard part done.
> > Look up the sum method.
> > http://www.w3schools.com/Xpath/xpath_functions.asp
> >
> > -----Original Message-----
> > From: CRANFORD, CHRIS [mailto:chris.cranf...@setech.com]
> > Sent: Friday, September 10, 2010 10:23 AM
> > To: fop-users@xmlgraphics.apache.org
> > Subject: XSLT Help
> >
> >
> > I am struggling with the best way to parse the following XML section
> > from my document with XSLT using FOP.
> >
> > <document>
> >   <usage>
> >     <record>
> >       <year>2010</year>
> >       <month>1</month>
> >       <quantity>1</quantity>
> >     </record>
> >     <record>
> >       <year>2009</year>
> >       <month>3</month>
> >       <quantity>2</quantity>
> >     </record>
> >   </usage>
> > </document>
> >
> > In the PDF output, what I actually need to be able to produce is to
> > take the current year (2010) and go backward a total of
> > 4 years.  The XML document could contain data in this section that
> > dates back prior to 2006 and that information is just not used in
> this
>
> > output.
> >
> >
> > The PDF should look like the following:
> >
> >      J F M A M J J A S O N D Total
> >      - - - - - - - - - - - - -----
> > 2010 1 0 0 0 0 0 0 0 0 0 0 0     1
> > 2009 0 0 2 0 0 0 0 0 0 0 0 0     2
> >
> > The XSLT starts with 2010, searches for data for month 1 and steps
by
> 1
> > until 12, keeping a total and then displays the yearly total,
> > decrements the year, resets the month to 1 and starts the process
> > over.
> >
> > During each step, I need to examine the XML document to find if data
> > exists for the year/month in /document/usage/record by those two
data
> > values and if not, default a 0 usage; otherwise read the value of
> > /quantity from the record.
> >
> > Anyone have any suggestions on the best way to do this?
> >
> > Chris
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
> > For additional commands, e-mail: fop-users-
> h...@xmlgraphics.apache.org
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
> > For additional commands, e-mail: fop-users-
> h...@xmlgraphics.apache.org
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org

 

Reply via email to