How to format table like Directory Search with XSLT

Discussion in 'XML' started by Luca, Dec 10, 2003.

  1. Luca

    Luca Guest

    Hi,

    have a problem with xslt posted below, this stylesheet format a table
    like Yahoo directory, but I need exclude (from xslt) all categ element
    without sublink element (in this case category with name categ2 and
    categ6 ) and format table in same manner....

    I have add a variable named numrows, for dynamic display rows, is
    possible?

    Can help me!

    XML Source
    =========================================================

    <?xml version="1.0" encoding="UTF-8"?>
    <ROOT>
    <categ name="categ1">
    <sublink name="link1"/>
    <sublink name="link2"/>
    </categ>
    <categ name="categ2"></categ>
    <categ name="categ3">
    <sublink name="link1"/>
    <sublink name="link5"/>
    <sublink name="link6"/>
    <sublink name="link1"/>
    <sublink name="link5"/>
    <sublink name="link6"/>
    </categ>
    <categ name="categ4">
    <sublink name="link1"/>
    <sublink name="link5"/>
    <sublink name="link6"/>
    <sublink name="link1"/>
    <sublink name="link5"/>
    <sublink name="link6"/>
    </categ>
    <categ name="categ5">
    <sublink name="link1"/>
    <sublink name="link5"/>
    <sublink name="link6"/>
    <sublink name="link1"/>
    <sublink name="link5"/>
    <sublink name="link6"/>
    </categ>
    <categ name="categ6"></categ>
    </ROOT>
    =========================================================

    XSLT Source
    =========================================================

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:param name="numcols" select="number(2)"/>
    <xsl:variable name="numrows" select="number(3)"/>
    <xsl:param name="max-item-in-row" select="number(3)"/>
    <xsl:variable name="auto-width" select="floor(100 div $numcols)"/>
    <xsl:template match="ROOT">
    <table>
    <xsl:apply-templates select="categ[position() mod $numcols = 1]"
    mode="row"></xsl:apply-templates>
    </table>
    </xsl:template>
    <xsl:template match="categ" mode="row">
    <tr>
    <xsl:apply-templates select=".|following-sibling::categ[position()
    &lt; $numcols]"></xsl:apply-templates>
    </tr>
    </xsl:template>
    <!-- Definisco un numero minimo di link da produrre all'interno di
    ogni riga, qui almeno 2 -->
    <xsl:template match="categ">
    <!--Limito il numero di righe da stampare-->
    <td width="{$auto-width}%" valign="top">
    Category:<xsl:value-of select="@name"/>
    <hr/>
    <xsl:for-each select="sublink[position()&lt;=$max-item-in-row]">
    <b>
    <xsl:value-of select="@name"/>,
    </b>
    </xsl:for-each>
    <br/>
    </td>
    </xsl:template>
    </xsl:stylesheet>
    =========================================================



    Thx to all!
     
    Luca, Dec 10, 2003
    #1
    1. Advertising

  2. Luca wrote:

    > have a problem with xslt posted below, this stylesheet format a table
    > like Yahoo directory, but I need exclude (from xslt) all categ element
    > without sublink element (in this case category with name categ2 and
    > categ6 ) and format table in same manner....
    >
    > I have add a variable named numrows, for dynamic display rows, is
    > possible?


    > <xsl:apply-templates select="categ[position() mod $numcols = 1]"
    > mode="row"></xsl:apply-templates>


    <xsl:apply-templates select="categ[*][position() mod $numcols = 1]"
    mode="row"></xsl:apply-templates>

    > <xsl:template match="categ" mode="row">
    > <tr>

    <!-- Here is your counter -->
    <td><xsl:value-of select="position()"/></td>
    > <xsl:apply-templates select=".|following-sibling::categ[position()
    > &lt; $numcols]"></xsl:apply-templates>


    <xsl:apply-templates select=".|following-sibling::categ[*][position()
    &lt; $numcols]"></xsl:apply-templates>

    --
    Oleg Tkachenko
    XML Insider
    http://www.tkachenko.com/blog
     
    Oleg Tkachenko, Dec 11, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TGFrc2htaSBOYXJheWFuYW4uUg==?=

    Google search result like site search!! How?

    =?Utf-8?B?TGFrc2htaSBOYXJheWFuYW4uUg==?=, May 5, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    682
    Lucas Tam
    May 6, 2005
  2. Patrick Kowalzick
    Replies:
    5
    Views:
    477
    Patrick Kowalzick
    Mar 14, 2006
  3. Abby Lee
    Replies:
    5
    Views:
    420
    Abby Lee
    Aug 2, 2004
  4. Adam Short
    Replies:
    2
    Views:
    435
    Bob Barrows [MVP]
    Apr 14, 2005
  5. Pito Salas

    XSLT-like search in a Ruby Hash

    Pito Salas, Aug 31, 2010, in forum: Ruby
    Replies:
    2
    Views:
    101
    Robert Klemme
    Aug 31, 2010
Loading...

Share This Page