What are Forward Slashes in XSLT for?

formatting, xsl-fo, xslt

Solution

The `select` attribute of `apply-templates` is an XPath expression which selects nodes from your input XML - in this case all the `bar` elements under the `foo` element which is the top-level element in the input document. The full details of XPath syntax can be found in the XPath specifications - XPath 2.0 if you're using the current XSLT version 2.0 and XPath 1.0 if you're stuck with the old XSLT version 1.0.

The template that will be applied to each of those nodes will be chosen by looking at their `match` patterns, and (roughly speaking) the "most specific" template that could apply to each node will be the one chosen. So if the only possible match is

<xsl:template match="bar">

then that will be chosen for all of them, but if there was also an

<xsl:template match="bar[1]">

then this would be used for the first `bar` and the less-specific template would be used for the others. The principle of separating the selection of which nodes to process from the decision on exactly how to process each one is something that takes a bit of getting used to when you first start out with XSLT but once you understand it it makes the language very powerful.

I would recommend you find a good XSLT tutorial online and work through that to gain a better understanding of the concepts.

Problem

I'm fairly new to XSLT and was wondering what the forward slashes are for. For example: xsl:apply-templates select="/foo/bar" What should the template name of the above apply-template be?

Original source