Creating Match Patterns

Creating Match Patterns

As you might expect from the discussion on how "child::MASS" can be abbreviated as "MASS" , and the use of patterns such as "/", "/PLANETS" , and so on, its going to take a little work to get thoroughly familiar with creating match patterns Chapter 4 is devoted to doing that.

Match patterns are a subset of the full XPath language, and you use them in <xsl:template> , <xsl:key> , and <xsl:number> . In particular, you can set the match attribute of <xsl:template> and <xsl:key> , and the count and from attributes of <xsl:number> to a pattern. The following list includes a few examples of match patterns; youll see many more in Chapter 4 during the detailed discussion on using Xpath to select nodes and attributes:

  • "/" Matches the root node

  • "*" Matches element nodes (not all nodes, which is a common mistake to make)

  • "PLANET" Matches <PLANET> elements

  • "PLANET/MASS" Matches all <MASS> elements that are children of a <PLANET> element

  • "//PLANET" Matches all <PLANET> elements descending from the root node

  • "." Matches the current node (technically, this is not a match pattern, but an XPath expression, as youll see in Chapter 7)

You can also use patterns in the select attribute of the <xsl:apply-templates> , <xsl:value-of> , <xsl:for-each> , <xsl:copy-of> , and <xsl: sort > elements; in fact, the select attribute of these elements can hold full XPath expressions and is not limited to just match patterns. The select attribute of <xsl:value-of> indicates for which child node you want the value, as follows :

 <xsl:template match="PLANET">         <TR>            <TD><xsl:value-of select="NAME"/></TD>            <TD><xsl:value-of select="MASS"/></TD>         <TD><xsl:value-of select="RADIUS/"></TD>         <TD><xsl:value-of select="DAY"/></TD>      </TR>  </xsl:template> 

Now its time to use the select attribute of <xsl:apply-templates> because doing so enables you to specify what template to use at what time.



Inside XSLT
Inside Xslt
ISBN: B0031W8M4K
EAN: N/A
Year: 2005
Pages: 196

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net