Re: Table Manipulation

On Thu, Feb 04 2010 05:51:26 +0000, anandhthiyagarajan@gmail.com wrote:
> Okay i will make you clear.
>
> Consider the xml
>
> <node>
>     <title>
>         <ingredients>
>             <name>Category</name>
>             <name>Noodles</name>
>             <name>Pizza</name>
>         </ingredients>
>         <ingredients>
>             <ingredient>
>                 <content>Fat</content>
>                 <description>aaaa</description>
>             </ingredient>
>         </ingredients>
>         <ingredients>
>             <ingredient>
>                 <content>Fat</content>
>                 <description>hgjhgk</description>
>             </ingredient>
>         </ingredients>
>     </title>
> </node>
>
>
> Consider the xsl:fo
>
> <xsl:template match="node/title">
>         <fo:block space-before="4mm" hyphenate="true">
>             <fo:table table-layout="fixed" width="7in"> 
>                 <xsl:for-each select="ingredients/name">
>                     <fo:table-column column-width="10pt" />

Use proportional-column-width [1]:

   <fo:table-column column-width="proportional-column-width(1)" />

>                 </xsl:for-each>
>                 <fo:table-header hyphenate="true">
>                     <xsl:for-each select="head">

As Aish pointed out, you don't have <head> or <row> elements in your
XML.

...
> I am attaching the output file
>
> http://old.nabble.com/file/p27448047/Table.doc Table.doc 
>
>
> Hope this would be clear.

That does make it clearer, thank you.

Your XML doesn't make it easy to achieve what you want since <name> is
separate from the rest of the information for an ingredient.

To "wrap" (or maybe "split") the table, it would be simplest if you used
XSLT 2.0 so you could use xsl:for-each-group [2].  E.g.,:

<xsl:template match="node/title">
  <xsl:for-each-group
    select="ingredients[ingredient]"
    group-starting-with="position() mod 3 = 1">
      <fo:table>
        <!-- There's a "CATEGORY" column in every table. -->
        <fo:table-column column-width="proportional-column-width(1)" />
        <xsl:for-each select="current-group()">
          <fo:table-column column-width="proportional-column-width(1)" />
        </xsl:for-each>
        <fo:table-header>
          <fo:table-row>
            <fo:table-cell>
              <!-- Select the "Category" name and convert to upper-case. -->
            </fo:table-cell>
            <xsl:for-each select="current-group()">
              <fo:table-cell>
                <!-- Select the appropriate name based on the position
                     of this ingredients among its siblings, not on its
                     position in the current group, then convert to
                     upper-case. -->
              </fo:table-cell>
            </xsl:for-each>
          </fo:table-row>
        </fo:table-header>
        <fo:table-body>
          <!-- "Within the sequence constructor, the context item is the
                initial item of the relevant group", so this makes one
                row for each ingredient in the first ingredients in the
                current group. -->
          <xsl:for-each select="ingredient">
            <xsl:variable name="content-number" select="position()"/>
            <fo:table-row>
              <fo:table-cell>
                <!-- value of content -->
              </fo:table-cell>
              <xsl:for-each select="current-group()">
                <fo:table-cell>
                  <!-- value of "ingredient[$content-number]/description" -->
                </fo:table-cell>
              </xsl:for-each>
            <fo:table-row>
          </xsl:for-each>
        </fo:table-body>
      </fo:table>
  </xsl:for-each-group>
</xsl:template>

Regards,


Tony Graham                         Tony.Graham@MenteithConsulting.com
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd                               XML Guild member
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2

[1] http://www.w3.org/TR/xsl11/#d0e5961
[2] http://www.w3.org/TR/xslt20/#grouping

Received on Thursday, 4 February 2010 11:56:01 UTC