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
-----Original Message-----
From: David Frankson [mailto:[EMAIL PROTECTED]]
Sent: Saturday, September 15, 2001 17:39
To: [EMAIL PROTECTED]
Subject: Unexplained text node XSLT beahvior?

    I'm getting strange XSLT behavior, and I'm wondering if you guys could explain it...
 
XML source:
 
<?xml version="1.0" encoding="UTF-8"?>
<XMLRoot><test1>Why is this text displayed?</test1><test2/></XMLRoot>
 
 
XSL source:
 
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
 <xsl:template match="//test2">
     <here/>
   </xsl:template>
</xsl:stylesheet>
 
 
Output:
 
<?xml version="1.0" encoding="UTF-8"?>
Why is this text displayed?<here/>
 
 
This should be re-producible in Xalan 2.2D10 and in Saxon 6.4.3.  Can anyone explain to me why the text node gets written out when the XSL does not even reference that section on the input XML?
 
Dave Frankson

Reply via email to