Re: [xsl] #Please Help: Nested conditions

Subject: Re: [xsl] #Please Help: Nested conditions
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 20 Feb 2004 14:42:07 -0500
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


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">
          <xsl:value-of select="TITLE"/>
       <xsl:if test="TROW/TH">
           <xsl:apply-templates select="TROW[TH]"/>
         <xsl:apply-templates select="TROW[TB]"/>

  <xsl:template match="TROW">

  <xsl:template match="TH|TB">

The XSL approach I have worked out so far is this:

Some important comments:

        <xsl:template match="TABLE">
                        <xsl:value-of select="Table-TITLE"/>
                <xsl:text disable-output-escaping="yes">
                <xsl:text disable-output-escaping="yes">

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!"


        <xsl:template match="ROW">
                                <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:


or, more simply:


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@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd. 
Box 266, Kars, Ontario CANADA K0A-2E0     +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness

XSL-List info and archive:

Current Thread