[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: math get maximum and subtract 1

Subject: Re: math get maximum and subtract 1
From: "sascha" <sascha@xxxxxxxxxx>
Date: Wed, 24 Jul 2002 20:22:13 +0200
xsl subtract
wow! thanks jeni-
i will try this out tomorrow... thanks for that :-))

sascha




----- Original Message -----
From: "Jeni Tennison" <jeni@xxxxxxxxxxxxxxxx>
To: "sascha" <sascha@xxxxxxxxxx>
Cc: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, July 24, 2002 7:27 PM
Subject: Re:  math get maximum and subtract 1


Hi Sascha,

> this is my whole input:
>
> <DESCRIPTION_TABLE>
>    <DESCRIPTION_ITEM col="0" row="0">
>     <LABEL>Verantwortlicher</LABEL>
>     <VALUE>Text</VALUE>
>    </DESCRIPTION_ITEM>
>    <DESCRIPTION_ITEM col="0" row="1">
>     <LABEL>Prozessziel</LABEL>
>     <VALUE>Text</VALUE>
>    </DESCRIPTION_ITEM>
>    <DESCRIPTION_ITEM col="0" row="2">
>     <LABEL>Messgrösse</LABEL>
>     <VALUE>Text</VALUE>
>    </DESCRIPTION_ITEM>
>    <DESCRIPTION_ITEM col="0" row="3">
>     <LABEL>Benötigte Informationen</LABEL>
>     <VALUE>Text</VALUE>
>    </DESCRIPTION_ITEM>
>    <DESCRIPTION_ITEM col="0" row="4">
>     <LABEL>Erzeugte Ergebnisse</LABEL>
>     <VALUE>Text</VALUE>
>    </DESCRIPTION_ITEM>
>    <DESCRIPTION_ITEM col="1" row="0">
>     <LABEL>Externe Vorschriften</LABEL>
>     <VALUE>Text</VALUE>
>    </DESCRIPTION_ITEM>
>    <DESCRIPTION_ITEM col="1" row="1">
>     <LABEL>Hinweise</LABEL>
>     <VALUE>Text</VALUE>
>    </DESCRIPTION_ITEM>
>    <DESCRIPTION_ITEM col="1" row="2">
>     <LABEL>Potenzial</LABEL>
>     <VALUE>Text</VALUE>
>    </DESCRIPTION_ITEM>
>    <DESCRIPTION_ITEM col="1" row="3">
>     <LABEL>Mitgeltende Unterlagen</LABEL>
>     <VALUE>Text</VALUE>
>    </DESCRIPTION_ITEM>
>    <DESCRIPTION_ITEM col="1" row="4">
>     <LABEL>Offene Fragen</LABEL>
>     <VALUE>Text</VALUE>
>    </DESCRIPTION_ITEM>
>   </DESCRIPTION_TABLE>

If your XML is organised like this (i.e. sorted so that the last cell
in the table is the last DESCRIPTION_ITEM in the DESCRIPTION_TABLE),
then it's not too difficult to get a count of the columns and rows,
actually -- just look at col and row attributes on the last
DESCRIPTION_ITEM within the DESCRIPTION_TABLE. The number of columns
is:

  DESCRIPTION_TABLE/DESCRIPTION_ITEM[last()]/@col + 1

and the number of rows is:

  DESCRIPTION_TABLE/DESCRIPTION_ITEM[last()]/@row + 1

> i need to make a table with 2 cols and 5 rows but there is no FOR -
> loop in XSL, right, so i have to use a xsl:for-each , i guess... but
> how?
>
> output is a <fo:table>

Then it's *much* easier than you think. fo:table doesn't require you
to group your cells into rows -- instead, you can use the starts-row
property on those cells that start a row.

First, the DESCRIPTION_TABLE maps onto your fo:table:

<xsl:template match="DESCRIPTION_TABLE">
  <fo:table>
    <fo:table-body>
      ...
    </fo:table-body>
  </fo:table>
</xsl:template>

Then you iterate over the DESCRIPTION_ITEMs in order to create the
cells. The DESCRIPTION_ITEMs need to be sorted by row, and by column
within the row, as follows:

<xsl:template match="DESCRIPTION_TABLE">
  <fo:table>
    <fo:table-body>
      <xsl:for-each select="DESCRIPTION_ITEM">
        <xsl:sort select="@row" data-type="number" />
        <xsl:sort select="@col" data-type="number" />
        <fo:cell>
          ...
          <xsl:apply-templates />
        </fo:cell>
      </xsl:for-each>
    </fo:table-body>
  </fo:table>
</xsl:template>

and if the DESCRIPTION_ITEM starts a row (i.e. its column number is 0)
then you add a 'starts-row' attribute with the value 'true':

<xsl:template match="DESCRIPTION_TABLE">
  <fo:table>
    <fo:table-body>
      <xsl:for-each select="DESCRIPTION_ITEM">
        <xsl:sort select="@row" data-type="number" />
        <xsl:sort select="@col" data-type="number" />
        <fo:cell>
          <xsl:if test="@col = 0">
            <xsl:attribute name="starts-row">true</xsl:attribute>
          </xsl:if>
          <xsl:apply-templates />
        </fo:cell>
      </xsl:for-each>
    </fo:table-body>
  </fo:table>
</xsl:template>

If you were having to group the cells into rows then it would be a bit
more complicated -- you'd have to use a grouping method. It would also
be trickier if you had missing cells.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.