[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] XSLT and unexpected text ouput?


Subject: RE: [xsl] XSLT and unexpected text ouput?
From: "Jon Schwartz \(Volt\)" <a-jonsch@xxxxxxxxxxxxx>
Date: Wed, 28 Apr 2004 10:22:45 -0700

That did it, thanks.  For the benefit of myself and others who are
relatively new at this, can you explain a little more about the how the
default template is used, and when it applies?

If I understand this right, the behavior of the default template is
simply to render the text contents of nodes.  The gotcha is that XSLT
must start with a definition of a root node match

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

The root node match says specifically apply this template WHATEVER,
which by implication means to ignore all other nodes off the root which
do NOT match this template.  Otherwise, if nodes are neither matched nor
excluded, the default template applies to them.  Is that it?

I assume the same thing can occur at other levels in the XML if I do not
do nested and explicit matches down through the hierarchy?

Thanks,

Jon Schwartz

-----Original Message-----
From: Brinkman, Theodore [mailto:Theodore.Brinkman@xxxxxxxxxxxxxxxxxxxx]

Sent: Wednesday, April 28, 2004 10:00 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] XSLT and unexpected text ouput?

Sounds like the default templates are being called.  You'll probably
need to do something like <xsl:template match="InsertMatchHere"/> to
replace the default templates with templates which don't output
anything.

For example, if I had some XML that looked like:
<root>
	<branch1>...content...</branch1>
	<othernode>...content...</othernode>
</root>

and an XSLT stylesheet which only had the following template:
<xsl:template match="branch1">
	...do stuff...
</xsl:template>

I would get all the leaf content of othernode underneath the branch1
processed output.  To avoid getting the othernode content, I would need
to add an 'empty' template to override the default template, like this:
<xsl:template match="othernode"/>

	- Theo

-----Original Message-----
From: Jon Schwartz (Volt) [mailto:a-jonsch@xxxxxxxxxxxxx]
Sent: Wednesday, April 28, 2004 12:52 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] XSLT and unexpected text ouput?


I have seen this only a couple times, and without giving away our future
product can't send XML and XSLT to demonstrate it.  But I'm hoping I can
describe the general behavior and one of you will have seen this kind of
thing before.

I am converting XML to HTML.  A chunk of XML content in one branch of
the XML tree is rendered as I want it to without a problem. But at the
bottom of the HTML file - in fact after my closing </HTML> - the text
content of a series of leaf nodes in an entirely different branch of the
XML are streamed onto the end of the file.  I have checked carefully and
tried tweaking data, I have stepped through this in XSelerator - there
is no XSLT match or code which is causing this to happen.

I tried switching the order of the XML branches, so that the one I want
to render is below the other in the file.  Now the leaf content from the
unwanted branch is streamed ABOVE the HTML that I want - so the behavior
IS dependent on the order in the XML.

I am using MSXML for the transform.  Have any of you seen this before?
A workaround would be greatly appreciated.

Thanks,

Jon Schwartz


Current Thread
Keywords