Matching an Element by its Position
You can also match elements based on a pattern using position qualifiers.
The syntax for matching an element by its position is
<xsl:template match="element[position-description]"
You can use the following position descriptions:
- • first-of-any()-The element must be the first sibling element.
- • first-of-type()-The element must be the first sibling of its type.
- • last-of-any()-The element must be the last sibling element.
- • last-of-type()-The element must be the last sibling of its type.
- • only-of-any()-The element must not have any sibling elements.
- • only-of-type()-The element must not have any sibling elements of the same type.
- • not-first-of-any()-The element must not be the first sibling element.
- • not-first-of-type()-The element must not be the first sibling of its type.
- • not-last-of-any()-The element must not be the last sibling element.
- • not-last-of-type()-The element must not be the last sibling of its type.
- • not-only-of-any()-The element must have one or more sibling elements.
- • not-only-of-type()-The element must have one or more element siblings of the same type.
For example, the XML template matches the last line element:
<xsl:template match= "line[last-of-type()]"
You can qualify these selectors by using the not keyword, so that the previous example could be rewritten so that it matches everything but the last line element:
<xsl:template match= "line[not last-of-type()]"