You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by "CRANFORD, CHRIS" <Ch...@setech.com> on 2010/09/10 16:23:17 UTC

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-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: XSLT Help

Posted by Syd Bauman <Sy...@Brown.edu>.
I'm not sure what you mean, but

   sum( //record[child::year='2009']/quantity )

seems to work for me.

> Actually, it appears the sum function to total the quantity is made
> for matching tags. Since you need to match the values I can't see
> an easy way to code that. I would just use a variable to sum up the
> quantity with a recursive call. You'll need a loop with a counter
> going 1 through 12 inside a loop with a counter from curyear to
> curyear - 3. You can loop using the recursive call. The best way to
> do it might depend on the structure of your data if known. Could
> there be more than 1 record with the same year and month? If not
> maybe try the previous suggestion using xsl:sort. If you want to
> allow multiples and not care if they exist and process them all in
> random order, try the recursion.

> <xsl:variable name="month_counter">0</xsl:variable>
> <xsl:choose>
> <xsl:when test="YEAR = $year_counter">
> <xsl:call-template name="count_month"><xsl:with-param
> name="month_counter" select="$month_counter + 1"/></xsl:call-template>
> </xsl:when>
> </xsl:choose>
> </xsl:template>
> <xsl:template name="count_month">
> <xsl:param name="month_counter"/>
> <xsl:if test="$month_counter < 12"><xsl:call-template
> name="count_month"><xsl:with-param name="month_counter"
> select="$month_counter + 1"/></xsl:call-template></xsl:if>

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


RE: XSLT Help

Posted by Eric Douglas <ed...@blockhouse.com>.
Actually, it appears the sum function to total the quantity is made for
matching tags.  Since you need to match the values I can't see an easy
way to code that.  I would just use a variable to sum up the quantity
with a recursive call.
You'll need a loop with a counter going 1 through 12 inside a loop with
a counter from curyear to curyear - 3.  You can loop using the recursive
call.
The best way to do it might depend on the structure of your data if
known.  Could there be more than 1 record with the same year and month?
If not maybe try the previous suggestion using xsl:sort.  If you want to
allow multiples and not care if they exist and process them all in
random order, try the recursion.
<xsl:variable name="month_counter">0</xsl:variable>
<xsl:choose>
<xsl:when test="YEAR = $year_counter">
<xsl:call-template name="count_month"><xsl:with-param
name="month_counter" select="$month_counter + 1"/></xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="count_month">
<xsl:param name="month_counter"/>
<xsl:if test="$month_counter < 12"><xsl:call-template
name="count_month"><xsl:with-param name="month_counter"
select="$month_counter + 1"/></xsl:call-template></xsl:if>


-----Original Message-----
From: CRANFORD, CHRIS [mailto:Chris.Cranford@setech.com] 
Sent: Friday, September 10, 2010 11:23 AM
To: fop-users@xmlgraphics.apache.org
Subject: RE: XSLT Help

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:edouglas@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.Cranford@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:edouglas@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.Cranford@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-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: XSLT Help

Posted by Syd Bauman <Sy...@Brown.edu>.
I think the previous advice to ask on the xsl-list (Mulberry) is
sound. I don't know for sure, but it strikes me that iterating over
records may not be the best approach. Perhaps something like the
following structure (untested) would help make things clearer.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
  xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="2.0">

  <xsl:variable name="current_year" select="year-from-date( current-date() )"/>

  <xsl:template match="/document">
    <!-- generate "J F M A M J J A S O N D Total" heading here -->
    <xsl:apply-templates select="usage[record/year[ number( . ) + 4 > $current_year ] ]">
      <xsl:sort select="record/year"/>
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="usage">
    <output-row-element>
      <!-- generate cell with year label here -->
      <xsl:apply-templates select="record">
        <xsl:sort select="month"/>
      </xsl:apply-templates>
      <!-- generate cell w/ total here -->
    </output-row-element>
  </xsl:template>
  
  <xsl:template match="record">
    <!-- generate cell w/ quantity here -->
  </xsl:template>

</xsl:stylesheet>

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


RE: XSLT Help

Posted by "CRANFORD, CHRIS" <Ch...@setech.com>.
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:lloyd@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
<Ch...@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:edouglas@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.Cranford@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:edouglas@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.Cranford@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-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: fop-users-
> help@xmlgraphics.apache.org
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: fop-users-
> help@xmlgraphics.apache.org
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>



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

 

Re: XSLT Help

Posted by Lloyd Cotten <ll...@lloydcotten.com>.
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-template-callbacks/

Lloyd

On Fri, Sep 10, 2010 at 12:53 PM, CRANFORD, CHRIS <Chris.Cranford@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:edouglas@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.Cranford@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:edouglas@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.Cranford@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-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail: fop-users-
> > help@xmlgraphics.apache.org
> > >
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail: fop-users-
> > help@xmlgraphics.apache.org
> > >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>
>

RE: XSLT Help

Posted by "CRANFORD, CHRIS" <Ch...@setech.com>.
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:edouglas@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.Cranford@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:edouglas@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.Cranford@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-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: fop-users-
> help@xmlgraphics.apache.org
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: fop-users-
> help@xmlgraphics.apache.org
> >
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 



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


RE: XSLT Help

Posted by Eric Douglas <ed...@blockhouse.com>.
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.Cranford@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:edouglas@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.Cranford@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-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 



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


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


RE: XSLT Help

Posted by "CRANFORD, CHRIS" <Ch...@setech.com>.
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:edouglas@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.Cranford@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-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 



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


RE: XSLT Help

Posted by Eric Douglas <ed...@blockhouse.com>.
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.Cranford@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-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


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


AW: XSLT Help

Posted by Georg Datterl <ge...@geneon.de>.
Hi Chris,

Yes, I suggest you to ask on the Mulberry Tech XSL list:

http://www.mulberrytech.com/xsl/xsl-list/index.html

You will have more chance to find XSLT specialists who will be able to help you.
[this message C&P from Vincent]

Regards,

Georg Datterl

------ Kontakt ------

Georg Datterl

Geneon media solutions gmbh
Gutenstetter Straße 8a
90449 Nürnberg

HRB Nürnberg: 17193
Geschäftsführer: Yong-Harry Steiert

Tel.: 0911/36 78 88 - 26
Fax: 0911/36 78 88 - 20

www.geneon.de

Weitere Mitglieder der Willmy MediaGroup:

IRS Integrated Realization Services GmbH:    www.irs-nbg.de
Willmy PrintMedia GmbH:                            www.willmy.de
Willmy Consult & Content GmbH:                 www.willmycc.de


-----Ursprüngliche Nachricht-----
Von: CRANFORD, CHRIS [mailto:Chris.Cranford@setech.com]
Gesendet: Freitag, 10. September 2010 16:23
An: fop-users@xmlgraphics.apache.org
Betreff: 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-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


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