RE: Conditional selection of Templates in XSL

Subject: RE: Conditional selection of Templates in XSL
From: "ciaran byrne" <ciaran.byrne@xxxxxxx>
Date: Tue, 29 Aug 2000 12:08:28 -0700
Hi Tony,
The advice that you gave me is definitely along the lines
of what I was looking for. You're correct in the sense
that I have nested HTML tables in my input, but don't
don't want nested tables in my output.

My only question is how do I handle the <tr> and <td> contained
within tables. I've tried something like..

<xsl:template match="tr[not(ancestor::Table)]> 

which I thought should select all the <tr> elements children of
the context node that don't have table ancestors (i.e. are not nested). 
The same would apply for <td> elements.
The XSL above doesn't work.  It actually seems to work in reverse order
i.e. it outputs <tr> for nested tables !!

Thanks for any help you could give.

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxx]On Behalf Of Tony Graham
Sent: Friday, August 25, 2000 3:57 PM
To: xsl-list@xxxxxxxxxxxxxxxx
Subject: Re: Conditional selection of Templates in XSL

At 24 Aug 2000 16:29 -0700, ciaran byrne wrote:
 > Hi all,
 > 	I'm attempting to select certain templates in my XSL
 > according to whether I've set a param to true or false.
 > Allow me to explain as follows:
 > In HTML tables can be nested. In my XML they can't.
 > So, I have a param set in my XSL that I pass a value into
 > using MSXML. If this value is set to 'true' then I want to
 > just extract the text from the table i.e. TABLE/text()
 > if it's false then I want to output the table and all the child
 > nodes that go with it.
 > Here is the type of XSL I'm attempting:
 > <xsl:template match="TABLE">
 > 	<xsl:choose>
 > 		<xsl:when test="$isFile = 'true'">
 > 			<xsl:call-template name="extractTable"/>
 > 		</xsl:when>
 > 		<xsl:otherwise>
 > 			<!-- Here I want to output the Table with all
 > 				it's child nodes such as <tr>,<td> etc. -->
 > 		</xsl:otherwise>
 > 	</xsl:choose>
 > 	<xsl:apply-templates/>
 > </xsl:template>

It sounds like you have nested HTML tables in your input, but you
don't want nested tables in your output.  Just use different template
rules for nested tables and unnested tables:

<xsl:template match="TABLE">

<xsl:template match="TABLE[ancestor::TABLE]">
  <xsl:value-of select="."/>

Note that the value of the TABLE element is the concatenation of all
of the text nodes that it contains, so you get the text inside the

Depending on your markup, you might need to use <xsl:strip-space
elements="TABLE TR"/> to get rid of superluous whitespace-only text

 > <!-- Does this mean that when called I only match against
 > the text node ????? -->
 > <xsl:template name="extractTable" match="TABLE/text()">
 > 	<xsl:value-of select="."/>
 > </xsl:template>

This means that you are matching text nodes that are children of TABLE
elements and adding their value to the result tree.

The likely result is that your adding to the result tree any
whitespace-only text nodes after the <table> tag, before the </table>
tag, and between the </tr> tags and their following <tr> tags.


Tony Graham
Tony Graham                            mailto:tgraham@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
17 West Jefferson Street                    Direct Phone: 301/315-9632
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
  Mulberry Technologies: A Consultancy Specializing in SGML and XML

 XSL-List info and archive:

 XSL-List info and archive:

Current Thread