Page 1 of 1

table formatting across same level nodes

Posted: Fri Nov 21, 2008 3:49 pm
by foutuguy
Hello,

I am stuck in the following problem. I would be so happy if someone could help me!
I have this kind of XML:

Code: Select all


<rootTag>
<Tag2>content of Tag2 - A</Tag2>
<Tag2>content of Tag2 - B</Tag2>
<Tag2>content of Tag2 - C</Tag2>
<Tag2>content of Tag2 - D</Tag2>
<Tag2>content of Tag2 - E</Tag2>
<Tag3>
<Tag4/>
</Tag3>
<Tag2>content of Tag2 - F</Tag2>
<Tag2>content of Tag2 - G</Tag2>
<Tag2>content of Tag2 - H</Tag2>
<Tag2>content of Tag2 - I</Tag2>
<Tag2>content of Tag2 - J</Tag2>
</rootTag>
In my XSL file, I currently have one table with headers for each Tag2 (i have attributes in reality in this tag but removed them to simplify things) +
a table per Tag3.

What I want to achieve:
I want to have one table for all the first Tag2 that are "following" each other (A to E) + a separate table for Tag3
+ a separate table for all the last Tag2 that are "following" each other (F to J).
Here is what I wrote for the Tag2 template. It does not work because inside the first <xsl:if>, I open a <table> tag that I not not close inside this <xsl:if> node. The same with the closing tag </table>

Code: Select all


<xsl:template match="Tag2">
<!-- If the last node (at the same level) is not Tag2,
this means this node is the first Tag2 of the list -->
<xsl:if test="name(preceding-sibling::*[last()]) != 'Tag2'">
<div class="CategoryTitle">Tag2</div>
<table cellpadding="0" cellspacing="0" border="1" width = "800">
<thead>
<tr>
<th>col1</th>
<th>col2</th>
<th>col3</th>
<th>col4</th>
</tr>
</thead>
</xsl:if>
<tr>
<td><xsl:apply-templates select="@col1"/></td>
<td><xsl:apply-templates select="@col2"/></td>
<td><xsl:apply-templates select="@col3"/></td>
<td width="400px"><xsl:apply-templates select="@col4"/></td>
</tr>
<!-- If the next node (at the same level) is not Tag2,
this means this node is the last Tag2 of the list -->
<xsl:if test="name(following-sibling::*[1]) != 'Tag2'">
</table>
</xsl:if>
</xsl:template>
If anybody would have a solution to achieve this, please let me know, Any help will be very appreciated.

Thanks very much in advance

Pierrot

Re: table formatting across same level nodes

Posted: Thu Dec 04, 2008 2:00 pm
by sorin_ristache
Hello,
foutuguy wrote:It does not work because inside the first <xsl:if>, I open a <table> tag that I not not close inside this <xsl:if> node. The same with the closing tag </table>
That is not allowed in an XSL stylesheet. The open tag and the close tag must be in the same node.

You can find many XSL experts who can fix your stylesheet quickly on xsl-list.


Regards,
Sorin