Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Inserting "wrong" tags [Thread Next] Re: Inserting "wrong" tagsTo: NULL Date: 5/4/2004 10:51:00 PM Am Wed, 21 Apr 2004 13:36:44 +0200 schrieb Oleg Tkachenko [MVP]:
> Michael Faschinger wrote:
>
>> I'm pretty new to XML so maybe my problem is trivial:
>> I want to transform the content of a simple XML-file[1] into a HTML-table
>> with XSL[2]. I have 4 elements, each representing one cell of the table,
>> but I don't want them to be placed into one row, but into a 2x2-table (or
>> in general: a mxn table, with given number n of columns).
>
> Here is classical solution:
> http://www.biglist.com/lists/xsl-list/archives/200101/msg00202.html
You helped me a lot, but today another problem appeared:
I want both automatic linebreaks and manual linebreaks. For example, the
output of [1] should contain a table with 3 rows and 2 columns, where the
second row contains only one cell (you can find the XSL-File at [2]). I
actually wrote these files by hand without testing them, so maybe they
don't work.
Is it possible to replace the <newrow/>-tag by </tr><tr>? The next problem
is, that cell (3,2) is the fifth cell, so the row-mode-transformation would
be applied instead of the "normal" transformation, although I do not want
this to happen!
I tried to use some kind of counter, that counts the number of cells in a
row and is resetted by the <newrow>-Tag, but as changing variables is not
possible, this does not work as well.
Thanks for your hints, regards, Michael
[1]
<?xml version="1.0"?>
<table>
<cell>1,1</cell>
<cell>1,2</cell>
<cell>2,1</cell>
<newrow/>
<cell>3,1</cell>
<cell>3,2</cell>
</table>
[2]
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="columns" select="2" />
<xsl:template match="/">
<html>
<body>
<table>
<xsl:apply-templates select="/table/cell[position() mod $columns=1]
mode = "row">
</table>
</body>
</html>
</xsl:template>
<xsl:template match="cell" mode="row">
<tr>
<td><xsl:value-of select="."/></td>
<xsl:apply-templates select="following-sibling::symbol[position() <
$columns]"/>
</tr>
</xsl:template>
<xsl:template match="cell">
<td><xsl:value-of select="."/></td>
</xsl:template>
</xsl:stylesheet>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
