Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Inserting "wrong" tags

From: Michael Faschinger <michivo@----.------.-->
To: 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() &lt;
$columns]"/>
  </tr>
 </xsl:template>

 <xsl:template match="cell">
  <td><xsl:value-of select="."/></td>
 </xsl:template>
</xsl:stylesheet>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent