xsl-list
[Top] [All Lists]

RE: [xsl] max from sequence problem

2007-02-10 02:03:29
It's a good idea with XSLT 2.0 to declare the types of your variables. Doing
this makes it less likely you will make such errors, and more likely that
when you do make errors, you will get good diagnostics.

In this case the problem is that <xsl:variable name="maxloads"> is
constructing a document node, so max($maxloads) is converting the
string-value of that document node to a number, which fails. Declare
maxloads as a sequence of integers, and all will be well.

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: Kent Seegmiller [mailto:hookjaw20(_at_)comcast(_dot_)net] 
Sent: 10 February 2007 01:31
To: XSLT
Subject: [xsl] max from sequence problem

I am trying to get the max sum of each grp/@name for each 
date/@name to scale it to a graph. I am using saxon8.7 
xslt2.0 but get the error:
Error line 19 ... 
FORG0001: Failure converting {1 1 5 4 1 19 19...} to a number

My source
<?xml version="1.0" encoding="UTF-8" ?> <allloads>
  <firstdate>2007-01-28</firstdate>
  <group name="PERISHABLE">
  <cons name="FROZEN">
  <date name="2007-01-28" skipdatecells="0">
  <grp name="1" count="1" skipcells="1" />
  <grp name="2" count="1" skipcells="0" />
  <grp name="3" count="1" skipcells="0" />
  </date>
  <date name="2007-01-29" skipdatecells="0">
  <grp name="1" count="2" skipcells="1" />
  <grp name="2" count="6" skipcells="0" />
  <grp name="3" count="3" skipcells="0" />
  </date>
  <date name="2007-01-30" skipdatecells="0">
  <grp name="0" count="7" skipcells="0" />
  <grp name="1" count="4" skipcells="0" />
  <grp name="2" count="1" skipcells="0" />
  </date>
  <date name="2007-01-31" skipdatecells="0">
  <grp name="0" count="2" skipcells="0" />
  <grp name="1" count="1" skipcells="0" />
  <grp name="2" count="3" skipcells="0" />
  </date>
  </cons>
  <cons name="DELI">
  <date name="2007-01-28" skipdatecells="0">
  <grp name="3" count="2" skipcells="3" />
  <grp name="4" count="1" skipcells="0" />
  <grp name="5" count="1" skipcells="0" />
  </date>
  <date name="2007-01-29" skipdatecells="0">
  <grp name="0" count="12" skipcells="0" />
  <grp name="1" count="10" skipcells="0" />
  <grp name="2" count="7" skipcells="0" />
  </date>
  <date name="2007-01-30" skipdatecells="0">
  <grp name="0" count="7" skipcells="0" />
  <grp name="1" count="4" skipcells="0" />
  <grp name="2" count="1" skipcells="0" />
  </date>
  <date name="2007-01-31" skipdatecells="0">
  <grp name="0" count="5" skipcells="0" />
  <grp name="1" count="3" skipcells="0" />
  <grp name="2" count="3" skipcells="0" />
  </date>
  </cons>
  </group>
  <group name="GROC">
  <cons name="GROC">
  <date name="2007-01-28" skipdatecells="0">
  <grp name="3" count="2" skipcells="3" />
  <grp name="4" count="3" skipcells="0" />
  </date>
  <date name="2007-01-29" skipdatecells="0">
  <grp name="0" count="9" skipcells="0" />
  <grp name="1" count="7" skipcells="0" />
  <grp name="2" count="6" skipcells="0" />
  </date>
  <date name="2007-01-30" skipdatecells="0">
  <grp name="0" count="16" skipcells="0" />
  <grp name="1" count="15" skipcells="0" />
  <grp name="2" count="9" skipcells="0" />
  </date>
  <date name="2007-01-31" skipdatecells="0">
  <grp name="0" count="7" skipcells="0" />
  <grp name="1" count="12" skipcells="0" />
  <grp name="2" count="9" skipcells="0" />
  </date>
  </cons>
  </group>
</allloads>



And my xsl:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="2.0"
                xmlns:xs="http://www.w3.org/2001/XMLSchema";
                xmlns:xdt="http://www.w3.org/2005/xpath-datatypes";>
<xsl:output method="xml"/>
<xsl:key name="grpdatetotal" match="grp" 
use="concat(../@name,'+',@name)"/>
<xsl:template match="/allloads">
<sums>
    <xsl:variable name="maxloads">
    <xsl:for-each-group select="./group/cons/date" group-by="@name">
      <xsl:variable name="dategroup" select="current-grouping-key()"/>
      <xsl:for-each-group select="current-group()" 
group-by="grp/@name">
      <xsl:variable name="groupGrp"
select="concat($dategroup,'+',current-grouping-key())"/>
      <xsl:sequence
select="sum(current-group()/key('grpdatetotal',$groupGrp)/@count)"/>
      </xsl:for-each-group>
    </xsl:for-each-group>
    </xsl:variable>
    <seq><xsl:value-of select="$maxloads"/></seq>
    <max><xsl:value-of select="max($maxloads)"/></max> 
</sums> </xsl:template>

</xsl:stylesheet>

What am I overlooking???  TIA

-Kent


--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>