|
Hi
David,
Xalan
works properly in this situation.
XSLT
specification defines two default templates (http://www.w3.org/TR/xslt#built-in-rule).
They work if you didn't overrode them. So your XSLT prepared for execution
will be:
<?xml
version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <!-- DEFAULT PART
-->
<!-- DT-1
-->
<xsl:template match="*|/">
<xsl:apply-templates/> </xsl:template> <!-- DT-2
--> <xsl:template
match="text()|@*"><xsl:value-of select="."/> </xsl:template> <!-- YOUR PART
-->
<xsl:template match="//test2"> <here/> </xsl:template> </xsl:stylesheet> So
when XSLT transformer starts execution, it takes document root as first
context node. Since you didn't specify template for root node it will use DT-1
(default template 1). Accroding this template XSLT processor runs instruction
<xsl:apply-templates/>, which selects all child elements and text nodes
and apply templates for them. So "XMLRoot" element is selected and the same DT-1
template applies to it. The same way "test1" element is selected and then
text-node inside of it. Text node with text "Why is this text displayed?" is
matched only by template DT-2 which executes <xsl:value-of select="."/>
which outputs text to the output document. Only after all these steps XSLT
processor iterates to node "test2", finds your template and outputs
result-element "here". That's why you get this output.
As a
conclusion I would advise you to put template for root to change default
behaviour:
<xsl:template match="/">
<xsl:apply-templates
select="//test2"/>
</xsl:template>
This
will save situation. I hope it will help you.
And
read specifications as these are core points of XSLT
specification and so Gary explained enough because this is
Xalan list, not XSLT list.
Thanks,
Dmitry
|
- Unexplained text node XSLT beahvior? David Frankson
- Voytenko, Dimitry
