RE: [xsl] #Please Help: Nested conditions

Subject: RE: [xsl] #Please Help: Nested conditions
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 21 Feb 2004 08:59:41 -0500
At 2004-02-20 22:18 +0100, Matthias Fischer wrote:
<Q>    <xsl:template match="TABLE">
<Q>      <TABLE>
<Q>          ...
<Q>         <xsl:if test="TROW/TH">
You are looking here for all <TH> that are children of a <TROW>;

Yes, that are children of the current node, which is TABLE. But I'm only testing the presence of such nodes, I'm not selecting them.


however, if I know that all <TH> will always be in a <TROW>, I could
write also <xsl:if test="TH">

No, because TH elements are not children of TABLE elements.


, couldn't I? Or would this imply here that
I would be looking for <TH> that are children of <TABLE>?

Yes, indeed it would.


<Q>             <xsl:apply-templates select="TROW[TH]"/>
A similar expression I have found in M. Kay's "XSLT P.R.2" at the item
"PredicateExpr". This is not where I would have looked for it, simply
because I've never heard the term "PredicateExpr"...

I'm selecting those TROW nodes that have TH children, rather than selecting the TH children of the TROW chidren.


Predicates are an essential component of writing useful XPath expressions.

<Q>       <xsl:copy><xsl:apply-templates/></xsl:copy>
I would have written:
                <TROW><xsl:apply-templates/></TROW>
but I assume it would have been the same. Correct?

In this case, yes, they are the same.


<Q> >                 <xsl:text disable-output-escaping="yes">
<Q> >                         &#60;&#47;TGROUP&#62;</xsl:text>
<Q> The above is expressly *not* the purpose of
<Q> disable-output-escaping= ...
I have used it as well to produce the DOCTYPE -- would that be ok?

That depends. If only DOCTYPE with a SYSTEM identifier, no ... use <xsl:output doctype-system=""/> for that purpose. If you have to write a DOCTYPE with an internal declaration subset, then yes (writing an internal declaration subset is the only reason I've ever used d-o-e=), though the pure design pattern for that would be to put the internal declaration subset into a separate file using a separate transformation and then point to it from your main transformation using the doctype-system= property.


I note that many of the element names in your original post are different than in your test data, so I've modified my example for you below as a working example.

I hope this helps.

........................ Ken


T:\ftemp>type matthias.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl"
href="D:\Daten\NEXUS\XML_FMaker\XSLT\NEXUS_XWare.xsl"?>
<XML>
<TITLE/>
<H1-H1>
<A ID="pgfId-492742"/>Descrizione funzionale</H1-H1>
<H2-H2>
<A ID="pgfId-507147"/>Uso previsto</H2-H2>
<A2-INSET-Source>
<A ID="pgfId-647166"/>Uso previsto della macchina descritta nel
presente manuale di istruzioni e la depurazione delle acque di scarico
urbane e/o industriali.</A2-INSET-Source>
<TABLE>
<CAPTION>
<Table-TITLE>
<A ID="pgfId-647169"/>
Processi di depurazione</Table-TITLE>
</CAPTION>
<ROW>
<TH ROWSPAN="1" COLSPAN="1">
<Table-HEADING>
<A ID="pgfId-647171"/>
Processi/sostanze</Table-HEADING>
</TH>
</ROW>
<ROW>
<CELL ROWSPAN="1" COLSPAN="1">
<Table-PARA>
<A ID="pgfId-647173"/>
Concentrazione di fanghi, sabbia od altri solidi in sospensione delle
acque</Table-PARA>
</CELL>
</ROW>
<ROW>
<CELL ROWSPAN="1" COLSPAN="1">
<Table-PARA>
<A ID="pgfId-647175"/>
Concentrazione di sabbie od altri solidi granulosi in sospensione nell'
acqua</Table-PARA>
</CELL>
</ROW>
<ROW>
<CELL ROWSPAN="1" COLSPAN="1">
<T2-Table-PARA>
<A ID="pgfId-647177"/>
Separazione di solidi grossolani trascinati da una corrente d'
acqua</T2-Table-PARA>
</CELL>
</ROW>
<ROW>
<CELL ROWSPAN="1" COLSPAN="1">
<Table-PARA>
<A ID="pgfId-647179"/>
Raccolta dei surnatanti presenti sulla superficie delle
acque</Table-PARA>
</CELL>
</ROW>
<ROW>
<CELL ROWSPAN="1" COLSPAN="1">
<Table-PARA>
<A ID="pgfId-647181"/>
Espulsione dei gas o vapori in sospensione nelle acque</Table-PARA>
</CELL>
</ROW>
</TABLE>
</XML>


T:\ftemp>type matthias.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

<xsl:output indent="yes"/>

<xsl:template match="/">
  <xsl:apply-templates select="/XML/TABLE"/>
</xsl:template>

<xsl:template match="TABLE">
  <TABLE>
      <TTITLE>
        <xsl:apply-templates select="CAPTION/Table-TITLE"/>
      </TTITLE>
     <xsl:if test="ROW/TH">
       <THEAD>
         <xsl:apply-templates select="ROW[TH]"/>
       </THEAD>
     </xsl:if>
     <TBODY>
       <xsl:apply-templates select="ROW[CELL]"/>
     </TBODY>
  </TABLE>
</xsl:template>

<xsl:template match="ROW">
   <TROW><xsl:apply-templates/></TROW>
</xsl:template>

<xsl:template match="TH|CELL">
   <TDATA><xsl:apply-templates/></TDATA>
</xsl:template>

<!--eat empty text nodes-->
<xsl:template match="text()[not(normalize-space())]"/>

</xsl:stylesheet>

T:\ftemp>saxon matthias.xml matthias.xsl
<?xml version="1.0" encoding="utf-8"?>
<TABLE>
   <TTITLE>
Processi di depurazione</TTITLE>
   <THEAD>
      <TROW>
         <TDATA>
Processi/sostanze</TDATA>
      </TROW>
   </THEAD>
   <TBODY>
      <TROW>
         <TDATA>
Concentrazione di fanghi, sabbia od altri solidi in sospensione delle
acque</TDATA>
      </TROW>
      <TROW>
         <TDATA>
Concentrazione di sabbie od altri solidi granulosi in sospensione nell'
acqua</TDATA>
      </TROW>
      <TROW>
         <TDATA>
Separazione di solidi grossolani trascinati da una corrente d'
acqua</TDATA>
      </TROW>
      <TROW>
         <TDATA>
Raccolta dei surnatanti presenti sulla superficie delle
acque</TDATA>
      </TROW>
      <TROW>
         <TDATA>
Espulsione dei gas o vapori in sospensione nelle acque</TDATA>
      </TROW>
   </TBODY>
</TABLE>



--
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.           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



Current Thread