This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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">
  <table>
    <xsl:apply-templates/>
  </table>
</xsl:template>

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

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

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

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

Regards,


Tony Graham
======================================================================
Tony Graham                            mailto:tgraham@mulberrytech.com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
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:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]