[Contents] [Prev] [Next] [Index] [Report an Error]


Context (Dot)

The current context node changes as an <xsl:apply-template> instruction traverses the document hierarchy and as an <xsl:for-each> instruction examines each node that matches an XPath expression. All relative node references are relative to the current context node. This node is abbreviated "." (read: dot) and can be referred to in XPath expressions, allowing explicit references to the current node.

The following example contains four uses for ".". The system node is saved in the system variable for use inside the <xsl:for-each> instruction, where the value of "." will have changed. The for-each select expression uses "." to mean the value of the name element. The "." is then used to pull the value of the name element into the <tag> element. The <xsl:if> test then uses "." to reference the value of the current context node.

<xsl:template match="system">
    <xsl:variable name="system" select="."/>
    <xsl:for-each select="name-server/name[starts-with(., '10.')]">
        <tag><xsl:value-of select="."/></tag>
        <xsl:if test=". = '10.1.1.1'">
            <match>
                <xsl:value-of select="$system/host-name"/>
            </match>
        </xsl:if>
    </xsl:for-each>
</xsl:template>



[Contents] [Prev] [Next] [Index] [Report an Error]