open HTML tags problem

R

ree32

I am new to XSL but I need to create a display where the layout is

<tr> <td> <item/ ></td> <td> <item/ ></td> </tr>
<tr> <td> <item/ ></td> <td> <item/ ></td> </tr>
and so on ..

A column table.

But inorder to this I am trying to do the following

<xsl:if test="position() mod 2 = 0">
<tr>
</xsl:if>

<xsl: something .. to add <td> <item/ ></td>

<xsl:if test="position() mod 2 = 0">
</tr>
</xsl:if>

But it wont let me use the open tag <tr>, is there a way around using
open tags. If not is there a solution to achieve what I am after ?
 
D

David Carlisle

I am new to XSL but I need to create a display where the layout is

<tr> <td> <item/ ></td> <td> <item/ ></td> </tr>
<tr> <td> <item/ ></td> <td> <item/ ></td> </tr>
and so on ..

A column table.

But inorder to this I am trying to do the following

<xsl:if test="position() mod 2 = 0">
<tr>
</xsl:if>

<xsl: something .. to add <td> <item/ ></td>

<xsl:if test="position() mod 2 = 0">
</tr>
</xsl:if>

But it wont let me use the open tag <tr>, is there a way around using
open tags. If not is there a solution to achieve what I am after ?

XSLT never works with tags, it generates a node tree, and you can't
have half a node. Also more directly, the stylesheet has to be a well
formed XML document.

You want to start a new row every second item, and in that row you want
to process this node and the next, so code that directly in xslt
in terms of this node tree, nit in trems of tags that may be used if
this node tree is ever serialised:


<xsl:for-each select="*[position() mod 2 = 0]">
<tr>
<xsl:apply-templates select=".|following-sibling::*[1]"/>
</tr>
</xsl:for-each>

<xsl:template match="abc">
<td>
<xsl:apply-templates/>
</td>
</xsl:templates>

David
 
R

ree32

Thanks so producing a 5 column table would be impossible as you can't
get a sibling 5 items down?
 
D

David Carlisle

Thanks so producing a 5 column table would be impossible as you can't
get a sibling 5 items down?

???

you can select any number of siblings. I just showed 2 as that's
what you asked for.If you want 5 then

<xsl:for-each select="*[position() mod 5 = 0]">
<tr>
<xsl:apply-templates select=".|following-sibling::*[position()&lt;5]"/>
</tr>
</xsl:for-each>

<xsl:template match="abc">
<td>
<xsl:apply-templates/>
</td>
</xsl:templates>

David
 

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,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top