XPath będziemy używali w kontekście
XSLT (XSL Transformations). Przykład
moria1.xsl:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/xhtml1/strict">
<xsl:output method="xml" indent="yes" encoding="utf-8"/>
<xsl:template match="/">
<html>
<head>
<title>Napewno strict wymaga</title>
</head>
<body>
<p>
Siła postaci
<xsl:value-of select="descendant::before/attribute::character"/>:
<xsl:value-of select="id('Gandalf')/child::strength/child::text()"/>
</p>
<p>
Siła postaci
<xsl:value-of select="//before/@character"/>:
<xsl:value-of select="id('Gandalf')/strength"/>
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
wykonujemy transformację na dokumencie moria-example.xml
$ xsltproc moria1.xsl moria-example.xml
i otrzymujemy
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/TR/xhtml1/strict">
<head>
<title>Napewno strict wymaga</title>
</head>
<body>
<p>
Siła postaci
Gandalf:
40</p>
<p>
Siła postaci
Gandalf:
40</p>
</body>
</html>