1 / 12

XPath and trees

XPath and trees. Elena Pierazzo 2006-2007. XPath. A language to describe how to locate a part of an XML document Used in many XML-based technologies and tools. XML documents: a tree view. <p> Here is some <hi type=" ital " > highlighted </hi> text. </p>. node. link.

milagro
Télécharger la présentation

XPath and trees

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XPath and trees Elena Pierazzo 2006-2007

  2. XPath • A language to describe how to locate a part of an XML document • Used in many XML-based technologies and tools

  3. XML documents: a tree view <p>Here is some <hi type="ital">highlighted</hi> text.</p> node link

  4. Or a genealogical chart Parent of <p> Ancestor of <hi>, @type, text nodes Child of / Siblings, descendant of /

  5. Other examples Let’s see some more examples

  6. Paths and Steps one step’s path <xsl:template match=“section”> <xsl:template match=“section/title”> / step operator (= child of) two steps’ path

  7. Abbreviated Syntax • / = child of E.g.: “section/title” Not the same as: /section/title • // = descendant of E.g.: “body//title” • * = any node E.g.: body/*/title • . = current node E.g.: .//para Not the same as //para

  8. XPath at work <AUTHOR TYPE="main">  <NAME><FIRST>Professor Christopher</FIRST><LAST>Gantley</LAST></NAME>  <AFFIL>University of Northumbria</AFFIL>  <EMAIL>c.gantley@unnx.ac.uk</EMAIL></AUTHOR><AUTHOR>  <NAME><FIRST>Megan</FIRST><LAST>Graham</LAST></NAME>  <AFFIL>Institute of Image Research, University of Northumbria</AFFIL>  <EMAIL>megan.graham@unnx.ac.uk</EMAIL></AUTHOR>

  9. We want obtain: Gantley, Professor Christopher <xsl:template match="NAME"><Ii><xsl:apply-templates select="LAST"/>, <xsl:apply-templates select="FIRST"/></i></xsl:template> Children of the contextual node Contextual node

  10. The select attribute • Has different meaning! • <xsl:template match=“node and descendant”> • <xsl:apply-templates select=“selected node”> • <xsl:value-of select=“text”>  forthcoming!

  11. Processing the text: value-of As it was: http://www.cch.kcl.ac.uk/legacy/teaching/av2001/xslt/class_mats/chap1/examples/eeyore.xsl How we can making it better: <xsl:template match="story"><html><head><title>Winnie-the-Pooh: <xsl:value-of select="/story/title"/></title></head><body><xsl:apply-templates/></body></html></xsl:template> Just text, not other nodes

  12. More examples • XML document: chap 2 > examples > abst10.xml • "Finished" template: chap 2 > examples > abstrs.xsl

More Related