Nic Miloslav     Example 73    KEYWORDS      EXAMPLES      AUTHORS     

Processing always starts with template match="/" . This is the root element and its only child is document element, in our case xslTutorial. Many stylesheets do not contain this element explicitly. When an explicit template does not exist implicit template, which contains instruction is called. This instruction means: processes all of the children of the current node, including text nodes. Compare Stylesheet 1 and Stylesheet 2. When template for a node exists, there is no default processing (Stylesheet 3). If you want to include descendants of the node, you have to explicitly request their templates (Stylesheet 4).


     XML     HOME     XSL 1     XSL 2     XSL 3     XSL 4      
<xslTutorial >
<AAA id='a1' pos='start'> 
      <BBB  id='b1'/> 
      <BBB  id='b2'/> 
</AAA> 
<AAA  id='a2'> 
      <BBB  id='b3'/> 
      <BBB  id='b4'/> 
      <CCC  id='c1'> 
           <DDD  id='d1'/> 
      </CCC> 
      <BBB  id='b5'> 
           <CCC  id='c2'/> 
      </BBB> 
</AAA> 
</xslTutorial>

     XSL 1     HOME     XML     HTML 1     OUTPUT 1     
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="AAA">
<DIV style="color:purple">
<xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
<xsl:value-of select="@id"/>
</DIV>
</xsl:template>
</xsl:stylesheet>

     HTML 1     HOME     XML     XSL 1     OUTPUT 1     
<DIV style="color:purple">AAA id=a1</DIV>
<DIV style="color:purple">AAA id=a2</DIV>

     OUTPUT 1     HOME     XML     XSL 1     HTML 1     
AAA id=a1
AAA id=a2

     XSL 2     HOME     XML     HTML 2     OUTPUT 2     
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<xsl:apply-templates/ >
</xsl:template>
<xsl:template match="/xslTutorial">
<xsl:apply-templates/ >
</xsl:template>
<xsl:template match="AAA">
<DIV style="color:purple">
<xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
<xsl:value-of select="@id"/>
</DIV>
</xsl:template>
</xsl:stylesheet>

     HTML 2     HOME     XML     XSL 2     OUTPUT 2     
<DIV style="color:purple">AAA id=a1</DIV>
<DIV style="color:purple">AAA id=a2</DIV>

     OUTPUT 2     HOME     XML     XSL 2     HTML 2     
AAA id=a1
AAA id=a2

     XSL 3     HOME     XML     HTML 3     OUTPUT 3     
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="AAA">
<DIV style="color:purple">
<xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
<xsl:value-of select="@id"/>
</DIV>
</xsl:template>
<xsl:template match="BBB">
<DIV style="color:blue">
<xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
<xsl:value-of select="@id"/>
</DIV>
</xsl:template>
<xsl:template match="CCC">
<DIV style="color:maroon">
<xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
<xsl:value-of select="@id"/>
</DIV>
</xsl:template>
<xsl:template match="DDD">
<DIV style="color:green">
<xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
<xsl:value-of select="@id"/>
</DIV>
</xsl:template>
</xsl:stylesheet>

     HTML 3     HOME     XML     XSL 3     OUTPUT 3     
<DIV style="color:purple">AAA id=a1</DIV>
<DIV style="color:purple">AAA id=a2</DIV>

     OUTPUT 3     HOME     XML     XSL 3     HTML 3     
AAA id=a1
AAA id=a2

     XSL 4     HOME     XML     HTML 4     OUTPUT 4     
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<xsl:apply-templates/ >
</xsl:template>
<xsl:template match="/xslTutorial">
<xsl:apply-templates/ >
</xsl:template>
<xsl:template match="AAA">
<DIV style="color:purple">
<xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
<xsl:value-of select="@id"/>
</DIV>
<xsl:apply-templates/ >
</xsl:template>
<xsl:template match="BBB">
<DIV style="color:blue">
<xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
<xsl:value-of select="@id"/>
</DIV>
<xsl:apply-templates/ >
</xsl:template>
<xsl:template match="CCC">
<DIV style="color:maroon">
<xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
<xsl:value-of select="@id"/>
</DIV>
<xsl:apply-templates/ >
</xsl:template>
<xsl:template match="DDD">
<DIV style="color:green">
<xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
<xsl:value-of select="@id"/>
</DIV>
</xsl:template>
</xsl:stylesheet>

     HTML 4     HOME     XML     XSL 4     OUTPUT 4     
<DIV style="color:purple">AAA id=a1</DIV>
<DIV style="color:blue">BBB id=b1</DIV>
<DIV style="color:blue">BBB id=b2</DIV>
<DIV style="color:purple">AAA id=a2</DIV>
<DIV style="color:blue">BBB id=b3</DIV>
<DIV style="color:blue">BBB id=b4</DIV>
<DIV style="color:maroon">CCC id=c1</DIV>
<DIV style="color:green">DDD id=d1</DIV>
<DIV style="color:blue">BBB id=b5</DIV>
<DIV style="color:maroon">CCC id=c2</DIV>

     OUTPUT 4     HOME     XML     XSL 4     HTML 4     
AAA id=a1
BBB id=b1
BBB id=b2
AAA id=a2
BBB id=b3
BBB id=b4
CCC id=c1
DDD id=d1
BBB id=b5
CCC id=c2