Subject: RE: RE: RE: [xsl] sum() Function Used With Variables From: "Ryan Lubben" <ryanl@xxxxxxxxxxx> Date: Wed, 14 Mar 2007 15:51:48 -0500 |
Thanks Charles. Unfortunately, we are tied to Xalan J and therefore XSLT 1.0 because that is what our CMS uses to publish. But I will certainly hang on to your code so that when we are able to use 2.0 I will be able to make it work. -----Original Message----- From: cknell@xxxxxxxxxx [mailto:cknell@xxxxxxxxxx] Sent: Wednesday, March 14, 2007 3:04 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: RE: RE: [xsl] sum() Function Used With Variables Here's a 2.0 stylesheet that solves the problem. You should be able to fiddle with it until it exactly matches your needs. <?xml version="1.0"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:strip-space elements="*" /> <xsl:output method="xml" indent="yes" encoding="UTF-8" /> <xsl:template match="/"> <xsl:apply-templates /> </xsl:template> <xsl:template match="informaltable"> <xsl:variable name="colwidths"> <cws> <xsl:call-template name="strip-in" /> </cws> </xsl:variable> <fo:block>Total Column Widths = <xsl:value-of select="sum($colwidths/cws/cw)"/></fo:block> </xsl:template> <xsl:template name="strip-in"> <xsl:for-each select="/informaltable/tgroup/colspec"> <cw><xsl:value-of select="translate(@colwidth,'in','')"/></cw> </xsl:for-each> </xsl:template> </xsl:stylesheet> -- Charles Knell cknell@xxxxxxxxxx - email -----Original Message----- From: Ryan Lubben <ryanl@xxxxxxxxxxx> Sent: Wed, 14 Mar 2007 14:55:56 -0500 To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Subject: RE: RE: [xsl] sum() Function Used With Variables Hi Charles, Trust me, the input XML file is well-formed and valid. What happens is that the processor begins to render the FO and quits part way through--always at the point in the stylesheet where it first encounters the variable that uses the sum() function. The missing end tag error is because the output XML/.fo file that has been created in memory is never completed and therefore is not well-formed. I have tried running the same input XML file and stylesheet from the command line using Xalan J and Saxon and I get the same results. Ryan -----Original Message----- From: cknell@xxxxxxxxxx [mailto:cknell@xxxxxxxxxx] Sent: Wednesday, March 14, 2007 2:38 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: RE: [xsl] sum() Function Used With Variables The Antenna House error is telling you that your input document is not well-formed. Specifically, you have an element with an opening tag that doesn't have a matching end tag. Is the Antenna House XSLT processor a 1.0 or a 2.0 processor? -- Charles Knell cknell@xxxxxxxxxx - email -----Original Message----- From: Ryan Lubben <ryanl@xxxxxxxxxxx> Sent: Wed, 14 Mar 2007 13:38:48 -0500 To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Subject: RE: [xsl] sum() Function Used With Variables Sorry Charles, I will try to elaborate some more. Here is a sample of the XML, my stylesheet code, as well as the error that I get from Antenna House when I try to render. XML TABLE <informaltable> <tgroup cols="2"> <colspec colname="col1" colwidth="1.5in"/> <colspec colname="col2" colwidth="2.0in"/> <tbody> <row> <entry colname="col1" > </entry> <entry colname="col2" > </entry> </row> </tbody> </tgroup> </informaltable> STYLESHEET <xsl:template match="informaltable"> <xsl:param name="colwidths"> <xsl:choose> <xsl:when test="contains(tgroup/colspec/@colwidth, 'in')"> <xsl:value-of select="substring-before(tgroup/colspec/@colwidth,'in')"/> </xsl:when> <xsl:otherwise>0</xsl:otherwise> </xsl:choose> </xsl:param> <xsl:param name="sum.colwidths" select="sum($colwidths)"/> <fo:block>Total Column Widths = <xsl:value-of select="$sum.columns"/> </fo:block> </xsl:template> ANTENNAHOUSE ERROR --- Format Abort --- 6145 (1801):Missing end tag. Line 477, Col 22, C:\DOCUME~1\ryanl\LOCALS~1\Temp\xif1078_54dc.xml source:XfoCommon::XmlParserImpl Thanks, Ryan -----Original Message----- From: cknell@xxxxxxxxxx [mailto:cknell@xxxxxxxxxx] Sent: Wednesday, March 14, 2007 1:24 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] sum() Function Used With Variables A sample of your input would help, and while I can grasp that "my stylesheet bottoms out" is not a good thing, it isn't specific enough to aid in diagnosing the problem. -- Charles Knell cknell@xxxxxxxxxx - email -----Original Message----- From: Ryan Lubben <ryanl@xxxxxxxxxxx> Sent: Wed, 14 Mar 2007 13:14:51 -0500 To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Subject: [xsl] sum() Function Used With Variables Hi All, I am currently attempting to use the sum() function in XSLT 1.0 to total up various table column widths in order to determine whether or not the table needs to span the entire width of the page. Unfortunately, the column width attribute that exists in the XML has the inches designator included in the width value. I have set my stylesheet up so that the 'in' designator is filtered through another variable using the substring-before() function, but as soon as I attempt to use the sum() function with the first variable my stylesheet bottoms out. Any help would be greatly appreciated. <xsl:param name="colwidths"> <xsl:choose> <xsl:when test="contains(tgroup/colspec/@colwidth, 'in')"> <xsl:value-of select="substring-before(tgroup/colspec/@colwidth,'in')"/> </xsl:when> <xsl:otherwise>0</xsl:otherwise> </xsl:choose> </xsl:param> <xsl:param name="sum.colwidths" select="sum($colwidths)"/> Thanks in advance. Ryan Lubben
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: RE: RE: [xsl] sum() Function Us, cknell | Thread | [xsl] xsl:function vs named templat, Jernigan, TieSha |
Re: [xsl] sum() Function Used With , Dimitre Novatchev | Date | Re: [xsl] FizzBuzz in XSLT 1.0. He, Abel Braaksma |
Month |