473,386 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to format table like Directory Search with XSLT

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
1 3130
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: simon | last post by:
I have virtual directory where I run test.asp page with only this code inside: <%Response.Write now()%> As a result, if I go into the IE and browse for the test.asp page, I get : 1/22/2004...
35
by: .:mmac:. | last post by:
I have a bunch of files (Playlist files for media player) and I am trying to create an automatically generated web page that includes the last 20 or 30 of these files. The files are created every...
0
by: Brendan Reynolds | last post by:
I have a web service that takes the XML representation of a dataset and uses XSLT to transform it to the format required to open a disconnected ADODB recordset on the XML, and returns the...
2
by: Paolo Pignatelli | last post by:
I am trying to get an output/file like this (below) in an XML file (MyXmlFile.xml) (which I will use for a slide show) -- <gallery timer="3" order="sequential" fadetime="2" looping="yes"...
6
by: dave | last post by:
I really have 2 questions regarding the following xml snippet. The xml is a directory representation. <?xml version="1.0" standalone="yes"?> <FileSystem> <Row> <ID>1</ID> <Name>Root</Name>...
3
by: sandeshmeda | last post by:
I have a XML file that is basically a Excel file saved as XML. I need to be able to change the XML into a different format. I was thinking one approach would be to: 1. Populate the dataset...
0
by: Omatase | last post by:
I have an xslt file I need to open at runtime. Here is my configuration: main assembly (dll) |-----xslt file unit test assembly I have a reference to my main assembly in my unit test...
0
by: news | last post by:
I'm trying to preview some HTML formatted text to show the context that a particular search result was found in. (does that make sense?) The idea is to take that HTML and display it as a stream...
1
by: Ken Fine | last post by:
I have set up Microsoft Search Server 2008 Express. I want to know how I can query against it and return results in a form that can be bound to ASP.NET controls like ListViews. If there's simply...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.