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

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

Match the Root
* Match the Root node by stating a the name of the RootElement. The formatting will be applied to every element from the XML document.

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

Match a Specific Element
* Match a specific element by stating the element name or its path. The formatting will be applied only to the stated element from the XML document.

The following 3 examples will all match the author element:

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

<xsl:template match="library/book/bookcataloginfo/author">
XSL file
View result

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

Match ChildElements
* Match ChildElements exactly by stating the name of the ParentElement, then the ChildElement. Separate the elements with a forward slash ( / ).

Example 1
* This first example matches all the content within the ParentElement node, chapter.

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

Example 2
* This example specifies the processing of every topic node regardless of its ParentElement node.

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

Example 3
* This example matches only the topic node that is a ChildElement of the ParentElement node, chapter.

* Note that the ParentElement node, subtopics, also contains several topic ChildElements that are NOT included in the final display. (They are not in red text.) This is because they are direct descendants of subtopics and not of the chapter element.

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

Example 4
* This example specifies the processing of ONLY every ChildElement topic node that is a direct descendant of the ParentElement node subtopic.

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

Attributes
* State the @ symbol to locate an element's attribute.

* The @ symbol may NOT be used within the <xsl:template match=""&> element. Therefore, the examples shown use the select attribute with the <xsl:apply-templates/> element. (More information about the select attribute with the <xsl:apply-templates/> element.)

The following has been added to the XML document used for these examples. Note that this content is NOT accessed.

<bookcataloginfo>
<title>NO ATTRIBUTE</title>
<author>NO ATTRIBUTE</author>
</bookcataloginfo>


Example 1
* This example specifies the processing of all bookcataloginfo elements that contain the isbn attribute.

<xsl:template match="bookcataloginfo">
<xsl:apply-templates select="@isbn"/>
XSL file
View result

Example 2A
1. This example tells the processor to look for all the chapter elements and access them only if they contain the attribute named number.

2. Since the processor is told to format only the number attribute's value by using the select attribute within the <xsl:apply-templates/> element, the values for the number attribute are each displayed within a paragraph element.

3. Note the formatting of the values for the number attribute and compare it with the next example.

<xsl:template match="chapter">
<xsl:apply-templates select="@number"/>
XSL file
View result

Example 2B
1. This example tells the processor to look for all the bookchapters elements and access them only if they contain the element of chapter if chpater also contains the attribute named number.

2. The processor is told to format only the number attribute's value by using the select attribute within the <xsl:apply-templates/> element.

3. Since the chapter element was also requested within the select attribute of <apply-template/> element, the values for the number attribute are all displayed on one line.

<xsl:template match="bookchapters">
<xsl:apply-templates select="chapter/@number"/>
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