XML.HTMLTeacher.Com
[Search] [Contact] [Sitemap]
XML
[Main]
[XPath]
[Classes]
[XHTML]
[XML]
[CSS]
[Design]
[Programming]
[Marketing]

Table of Contents
1. Overview
2. Match Patterns
3. Path Expressions
4. Tutorial/Lab

* The <xsl:apply-templates/> element has been used for each of these examples.
* These Path Expressions may also be used for attributes. See Attributes located under Match Patterns.
* This XML file was used for all the examples.

Single Forward Slash   /  
* Match the Root node by stating a single forward slash or a single forward slash followed by the name of the RootElement. The formatting will be applied to every element from the XML document.

Example 1
<xsl:template match="/">
XSL file
View result

Example 2
<xsl:template match="/library">
XSL file
View result

Example 3
* If a SINGLE forward slash is stated BEFORE the chapter element, no display would be seen. The reason for the non-display is because chapter is not a direct ChildElement of the ParentElement library.

<xsl:template match="/chapter">
XSL file
View result

Double Forward Slash   //  
* When double forward slashes are used, the processor will look from the Root node for ALL the ChildElements with the stated name.

Example 1
In the following example, the processor will look for all the ChildElements named chapter from the Root node of library.

<xsl:template match="//chapter">
XSL file
View result

Access Nodes Regardless of Parent
* The double forward slash will access all the named elements regardless of that named element's ParentElement.

Example 1A
* In the following example, ONLY the topic nodes that are DIRECTLY descended from the chapter element will be accessed. Note that the topic nodes that are a ChildElement of subtopic ARE NOT accessed.

<xsl:template match="chapter/topic">

XSL file
View result

Example 1B
* In the following example, ALL the topic nodes will be accessed from the ParentElement of chapter. Note that any topic nodes that are a ChildElement of subtopic WILL now be accessed.

<xsl:template match="chapter//topic">

XSL file
View result

Example 1C
* In the following example, ALL the topic nodes will be accessed from any ParentElement.

<xsl:template match="//topic">

XSL file
View result

Pipe Key   |  
* Use the pipe key to access two paths at the same time.

<xsl:template match="bookcataloginfo | chapter">

* To apply formatting separately to each of the accessed element sets, the select attribute has been added to the <xsl:apply-templates/> element. The select attribute states more specifically exactly which elements of a particular ParentElement will be accessed and where it will be placed in the html document. (More information about the select attribute with the <xsl:apply-templates/> element.)

<p><span style="color:red;">
<xsl:apply-templates select="title"/>
</span></p>

<p><span style="color:green;">
<xsl:apply-templates select="subtitle"/>
</span></p>

XSL file
View result



All materials, tutorials and content are copyrighted by HTMLTeacher.Com.
Any use of any material, tutorials and/or content provided by this site is prohibited without expressed written consent of the author.

Copyright ©2003 HTMLTeacher.Com and Sonia Weimann