Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSL xsl:template match="/"

I am just learning XML and how to use XSL files. In an XSL file I found the following term:

xsl:template match="/" 

What does this stand for? And what could I use instead of the /? Could I write table or any other HTML tag instead of /?

like image 678
Pat Avatar asked Jun 27 '10 10:06

Pat


People also ask

What is xsl template match?

XSLT <xsl:template>The match attribute is used to associate the template with an XML element. The match attribute can also be used to define a template for a whole branch of the XML document (i.e. match="/" defines the whole document).

How do xsl templates work?

The template tells the XSLT processor how to format a particular output from the XML source document. The perfect determination is made to the nodes in the node-set with the pattern matching within the XSL template. The syntax of the XSLT template is given here and this helps in optimizing the stylesheets.

What is xsl apply template?

XSLT apply-templates define how to find elements and help in removing unwanted text in the document. It applies a template rule to the current child nodes. It adds a select attribute along with the template to specify the order of child nodes to process the current task with the help of the XSLT processor.

How do you call a template in XSLT?

The xsl:call-template element is used to invoke a template by name. By invoke, we mean that the named template is called and applied to the source document. If a template does not have a name, it cannot be called by this element. The xsl:template element is used to create a template.


1 Answers

The value of the match attribute of the <xsl:template> instruction must be a match pattern.

Match patterns form a subset of the set of all possible XPath expressions. The first, natural, limitation is that a match pattern must select a set of nodes. There are also other limitations. In particular, reverse axes are not allowed in the location steps (but can be specified within the predicates). Also, no variable or parameter references are allowed in XSLT 1.0, but using these is legal in XSLT 2.x.

/ in XPath denotes the root or document node. In XPath 2.0 (and hence XSLT 2.x) this can also be written as document-node().

A match pattern can contain the // abbreviation.

Examples of match patterns:

<xsl:template match="table"> 

can be applied on any element named table.

<xsl:template match="x/y"> 

can be applied on any element named y whose parent is an element named x.

<xsl:template match="*"> 

can be applied to any element.

<xsl:template match="/*"> 

can be applied only to the top element of an XML document.

<xsl:template match="@*"> 

can be applied to any attribute.

<xsl:template match="text()"> 

can be applied to any text node.

<xsl:template match="comment()"> 

can be applied to any comment node.

<xsl:template match="processing-instruction()"> 

can be applied to any processing instruction node.

<xsl:template match="node()"> 

can be applied to any node: element, text, comment or processing instructon.

like image 97
Dimitre Novatchev Avatar answered Oct 07 '22 17:10

Dimitre Novatchev