xsl-list
[Top] [All Lists]

Re: #Please Help: Nested conditions

2004-02-20 12:57:05
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>
...
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.
...
                <xsl:text disable-output-escaping="yes">
Never ever use disable-output-escaping without reason.

>            <xsl:when test="element-available('TH')">
You got something seriously wrong here too. The element-available()
function is for dealing with extension elements in the style sheet.

> However, this approach does not work. What am I doing wrong?
Well, I'd recommend to buy an XSLT book first and start reading
it at the beginning.

In XSLT you select the elements you want to process in advance. The
following will wrap the TROW elements containing TH elements in a THEAD
and everything else in a TBODY. Unfortunately, your prose description
is utterly inconsistent with the provided code, so I can't give more
hints.
  <xsl:template match="table">
    <xsl:copy>
       <xsl:copy-of select="TITLE"/>
       <xsl:if test="TROW[TH]">
         <THEAD>
            <xsl:apply-templates select="TROW[TH]"/>
         </THEAD>
       </xsl:if>
       <xsl:if test="TROW[not(TH)]">
         <TBODY>
            <xsl:apply-templates select="TROW[not(TH)]"/>
         </TBODY>
       </xsl:if>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="node()|@*>
    <xsl:copy>
      <xsl:apply-templates select="node()|@*/>
    </xsl:copy>
  </xsl:template>

J.Pietschmann

XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>