Figure 2   Using Patterns with XSL
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="uri:xsl">  
    <xsl:template match="/">
        <HTML><BODY><TABLE>
        <xsl:for-each select="order/item">
            <TR>
                <TD><xsl:value-of select="name"></TD>
                <TD><xsl:value-of select="price"></TD>
            </TR>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Figure 4   XSL Pattern Syntax

Character
Description
/
Child operator: selects immediate children of the left-side collection. When this path operator appears at the start of the pattern, it indicates that children should be selected from the root node.
//
Recursive descent: searches for the specified element at any depth. When this path appears at the start of the pattern, it indicates recursive descent from the root node.
.
Indicates the current context.
*
Wildcard: selects all elements regardless of the element name.
@
Attribute: prefix for an attribute name.
:
Namespace separator: separates the namespace prefix from the element or attribute name.
!
Applies the specified method to the reference node.
( )
Groups operations to explicitly establish precedence.
[ ]
Applies a filter pattern.
[ ]
Subscript operator: used for indexing within a collection.


Figure 5   XSL Pattern Examples

Pattern
Description
order/item/price
Identifies price elements within item elements within order elements within the current context.
order/*/price
Identifies price elements that are grandchildren of order elements within the current context.
order//price
Identifies price elements that exist anywhere within an order element within the current context.
//item/price
Identifies price elements within item elements that exist anywhere within the document.
.//price
Identifies price elements that exist anywhere within the current context.


Figure 6   Collection Methods

Method
Description
ancestor
Finds the nearest ancestor matching the pattern. It returns either a single element result or null.
attribute
Returns the collection of all attribute nodes. If the optional text parameter is provided, it returns only attributes matching that particular name.
comment
Returns the collection of comment nodes.
element
Returns the collection of all element nodes. If the optional text parameter is provided, it returns only element children matching that particular name.
node
Returns the collection of all nonattribute nodes.
pi
Returns the collection of processor instruction nodes for the particular document.
textnode
Returns the collection of text nodes for the particular document.


Figure 7   Information Methods

Method
Description
date
Casts values to date format
end
Returns true for the last element in a collection
index
Returns the index number of the node within the parent
nodeName
Specifies the tag name of the node, including the namespace prefix
nodeType
Returns a number to indicate the type of the node
text
Specifies the text contained within the element
value
Returns a type cast version of the value of an element


Figure 8   Expression Operators

Operator
Shortcut
Description
$and$
&&
Logical-and
$or$
||
Logical-or
$not$

Negation
$eq$
=
Equality
$ieq$

Case-insensitive equality
$ne$
!=
Not equal
$ine$

Case-insensitive inequality
$lt$
<
Less than
$ilt$

Case-insensitive less than
$le$
<=
Less than or equal
$ile$

Case-insensitive less than or equal
$gt$
>
Greater than
$igt$

Case-insensitive greater than
$ge$
>=
Greater than or equal
$ige$

Case-insensitive greater than or equal
$all$

Set operation; returns TRUE if the condition is true for all items in the collection
$any$

Set operation; returns TRUE if the condition is true for any item in the collection


Figure 9   DHTML Query Page


<!--  1999, Aaron Skonnard, http://www.skonnard.com
      Written for Microsoft Internet Developer, Inside Knowledge -->

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft FrontPage 4.0">
<LINK rel="stylesheet" type="text/css" href="main.css">
<TITLE>Pattern Matching Syntax Tool</TITLE>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--

function btnSelectNodes_onclick() {
    var strResult = "";
    nl = xmlSource.SelectNodes(pattern.value);
    for (i=0; i<nl.length; i++) {
        n = nl.item(i);
        strResult += n.xml + "\r\n\r\n";
    }
    divResults.innerText = strResult;
}

function btnSingleNode_onclick() {
    var strResult = "";
    n = xmlSource.SelectSingleNode(pattern.value);
    strResult = n.xml;
    divResults.innerText = strResult;
}

function btnLoad_onclick() {
    xmlSource.src = form1.file.value;
    form1.action = form1.file.value;
}

//-->
</SCRIPT>
</HEAD>
<BODY>

<!-- XML Data Islands -->
<XML id=xmlSource src = 
orders.xml></XML>

<H1>Pattern Syntax Demo</H1>

<TABLE width="100%" height="100%">
<TR>
<TD valign=top width="40%">

<h3>XML Source:</h3>
<IFRAME id=xmlFrame name=xmlFrame class=sourcexml 
src="orders.xml" width=400 height="80%">
</IFRAME><br>
<br>
<FORM action="" method=get id=form1 name=form1 target=xmlFrame>
<INPUT id=file name=file size=30 >
<INPUT type="submit" value="Load" 
	id=btnLoad name=btnLoad LANGUAGE=javascript onclick=
	"return btnLoad_onclick()"> 
</FORM>
<br>
</TD>

<TD valign=top align=left>

<h3>Enter Pattern String:</h3><TEXTAREA cols=40 id=pattern name=pattern rows=3>
</TEXTAREA><br>
<INPUT type="button" value="SelectNodes"
 id=btnSelectNodes name=btnSelectNodes LANGUAGE=javascript
 onclick="return btnSelectNodes_onclick()">&nbsp;
&nbsp;
<INPUT type="button" value="SelectSingleNode" 
id=btnSingleNode name=btnSingleNode LANGUAGE=javascript 
onclick="return btnSingleNode_onclick()">


<h3>Result Collection:</h3>
<DIV class=results id=divResults></DIV>

</TD>
</TR>
</TABLE>
</BODY>
</HTML>