Laboratorium XML
wtorek 11.00—12.30
»Home
»Materiały
  »DTD & co.
  »SAX
  »DOM
  »Zadanie 2
  »XPath
  »XSLT
  »Simple
  »JDOM
  »JS
»Odnośniki
  »Xerces2
»Zadania

XPath

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()"/>
          <!-- converted as with string() -->
        </p>
        <p>
          Siła postaci
          <xsl:value-of select="//before/@character"/>:
          <xsl:value-of select="id('Gandalf')/strength"/>
          <!-- converted as with string() -->
        </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>

Axis (oś? wzdłuż której wybieramy atrybuty)

Pełne pokrycie dokumentu

      preciding
ancestor self descendant
      following

Domyślną osią jest child

    preciding
        preciding-sibling

ancestor-or-self    descedant-or-self
ancestor parent self child descendant
                     attribute
                     namespace

        following-sibling
    following