XSL / DocBook Question - Trying to generate a table, how to handlerows

M

Mike

Hello,

I have a newbie-type problem I'm trying to solve.

First, note that I'm relatively new to both XSL and DocBook.

Anyway, I'm trying to transform a portion of an XML document into a
DocBook table, using XSLT.

I thought the following logic might work, but it doesn't seem to (saxon
complains that "row" must be terminated by matching end-tag "</row>").
Note that this is a simplified example from my actual stylesheet:

<xsl:template match="mm:MyContainerElement">
<sect1>
<table>
<title>My Table</title>
<tgroup cols="3">
<tbody>
<xsl:for-each select="mm:MyEntryItem">
<xsl:if test="(position() = 1) or
((position() &gt;= 3) and (position() mod 3 = 0))">
<row>
</xsl:if>
<entry>
<xsl:value-of select="@name"/>
</entry>
<xsl:if test="(position() = last()) or
(((position() + 1) &gt;= 3) and ((position() + 1) mod 3 = 0))">
</row>
</xsl:if>
</xsl:for-each>
</tbody>
</tgroup>
</table>
</sect1>
</xsl:template>


Basically, what I _wanted_ to do was to create a table with 3 columns
and however many rows as needed. The idea above was to start a new
<row> element at the beginning of every 3 columns, and to end each
</row> at the end of every 3 columns. (Note that I didn't get to
actually test my logic above.)

But that doesn't seem to work. From what I've read, I think the problem
is with my thinking (imperative vs declarative programming.)

Any help would be appreciated. I'm sorry if this type of question has
been asked before - I'm sure it has - but I'm having a bit of a problem
making the leap from imperative to declarative-style thinking.

BY THE WAY: Why can't <table> offer (as an option) something like
<simplelist>, where you can just specify the number of columns, and then
you just add <member>'s - no need to specify rows? I would use
<simplelist>, but it doesn't offer all the formatting options that
<table> does.

Thanks,

Mike
 
J

Joseph Kesselman

XSLT styleshets are XML documents. That means they must be well-formed.
That means you can't issue <row> from within one element and </row> from
within another.

Restructure the problem so it's properly hierarchical -- describe how to
produce row elements with appropriate content, rather than trying to
insert start-row and end-row tags.

You may want to look at the XSLT FAQ website, which has a section that
deals with tabularizing data.
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top