So far, we can either apply the default behavior to an element node (processing the entire element content) or completely override it (ignoring all the element content). It would be practical to have the possibility to activate the rules for certain sub-elements but not for all.
This is the effect of the xsl:apply-templates element. This element has a select attribute that contains an XPath expression telling which descendant nodes of an element node should be processed. The XPath expression should return a node set. If the select is omitted, then all descendant nodes of the element should be processed. The context for the XPath expression, that is, the element whose descendants must be selected, is set by the match attribute of the xsl:template element that contains the xsl:apply-templates element.
For instance, the following stylesheet selects the article children of the dblp elements. Only these elements should be processed. Since there is no specific rule for them, the built-in rules are applied and the article content is printed.
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="dblp"> All the journal papers: <xsl:apply-templates select="article"/> </xsl:template> </xsl:stylesheet>
The result document follows:
<?xml version="1.0" encoding="UTF-8"?> All the journal papers: M. Franceschet B. ten Cate Guarded fragments with constants Journal of Logic, Language and Information 14 3 281-288 2005 http://www.sci.unich.it/~francesc/pubs/jlli05.pdf