At 2004-02-20 20:13 +0100, Matthias Fischer wrote:
Can anyone please help me? O have the following problem I cannot solve:
I am trying to transform a table structure which is, simplified, like
this:
<TABLE>
<TITLE>...</TITLE>
<TROW>
<TH>
...
</TH>
</TROW>
<TROW>
<CELL>
...
</CELL>
</TROW>
...
</TABLE>
The availability and number of <TROW> elements with a nested <TH> or,
respectively, with a nested <TB> varies.
I'm assuming your <CELL> elements in your example are <TB> elements?
The objective is to drop the <TH>'s and <TB>'s, and to wrap all <TROW>'s
that before contained a <TH> into a single <THEAD> element, and
similarly to wrap all <TROW>'s that before contained a <TB> into a
single <TBODY> element.
Your code includes a footer element ... how does one distinguish header
rows from footer rows? From their position around the body rows?
The following is untested but shows the testing of grandchildren and the
processing of rows. If you provided a complete test file, then volunteers
might find the time to actually test their submissions for you.
<xsl:template match="TABLE">
<TABLE>
<TTITLE>
<xsl:value-of select="TITLE"/>
</TTITLE>
<xsl:if test="TROW/TH">
<THEAD>
<xsl:apply-templates select="TROW[TH]"/>
</THEAD>
</xsl:if>
<TBODY>
<xsl:apply-templates select="TROW[TB]"/>
</TBODY>
</TABLE>
</xsl:template>
<xsl:template match="TROW">
<xsl:copy><xsl:apply-templates/></xsl:copy>
</xsl:template>
<xsl:template match="TH|TB">
<TDATA><xsl:apply-templates/></TDATA>
</xsl:template>
The XSL approach I have worked out so far is this:
Some important comments:
<xsl:template match="TABLE">
<TABLE>
<TTITLE>
<xsl:value-of select="Table-TITLE"/>
</TTITLE>
<xsl:text disable-output-escaping="yes">
<TGROUP></xsl:text>
<xsl:apply-templates/>
<xsl:text disable-output-escaping="yes">
</TGROUP></xsl:text>
The above is expressly *not* the purpose of disable-output-escaping= ... it
is a last resort only and not used for instance markup. There are very
(very!) few occasions where d-o-e= is a candidate for use.
My guidance to my students is: "if you think you need d-o-e=, think again!"
</TABLE>
</xsl:template>
<xsl:template match="ROW">
<xsl:choose>
<xsl:when test="element-available('TH')">
The above is *not* the purpose of element-available() ... that is a
function call that returns true/false on the presence of an extension
element or an XSLT element implementation in the XSLT engine that is
running the stylesheet.
To test the presence of a child element named 'TH', do either:
test="child::TH"
or, more simply:
test="TH"
However, this approach does not work. What am I doing wrong?
A number of things that I have hopefully illustrated for you above.
................... Ken
--
Public courses: upcoming world tour of hands-on XSL training events
Each week: Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO
Washington, DC: 2004-03-15 San Francisco, CA: 2004-03-22
Hong Kong: 2004-05-17 Germany: 2004-05-24 England: 2004-06-07
World-wide on-site corporate, government & user group XML training!
G. Ken Holman mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list