By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,402 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,402 IT Pros & Developers. It's quick & easy.

How to format table like Directory Search with XSLT

P: n/a
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!
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.