How to format table like Directory Search with XSLT

L

Luca

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>
</b>
</xsl:for-each>
<br/>
</td>
</xsl:template>
</xsl:stylesheet>
=========================================================



Thx to all!
 
O

Oleg Tkachenko

Luca said:
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"> said:
<xsl:template match="categ" mode="row">
<tr>
<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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top