1 / 8

Using Long Names for Xpath Expressions

Using Long Names for Xpath Expressions. Roger L. Costello XML Technologies. Problem: iterate through ancestors. Suppose that in your stylesheet you are at an arbitrary node in the XML tree. How would you output the name of all of its ancestor nodes?. Will this work:

caelan
Télécharger la présentation

Using Long Names for Xpath Expressions

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. Using Long Names for Xpath Expressions Roger L. Costello XML Technologies

  2. Problem: iterate through ancestors • Suppose that in your stylesheet you are at an arbitrary node in the XML tree. How would you output the name of all of its ancestor nodes? Will this work: <xsl:value-of select="name(..)"/> <xsl:value-of select="name(../..)"/> <xsl:value-of select="name(../../..)"/> How many of these should we do? We don't know since we are at an arbitrary node!

  3. Problem: get the previous sibling and following sibling • Suppose that in your stylesheet you are at an arbitrary node in the XML tree. How would you output the name of its previous sibling and following sibling?

  4. Long Notation • Thus far we have used the abbreviated notation for expressing a path to a node. As we see there are some things for which the abbreviated notation is inadequate • The long notation gives you the ability to express things that can't be expressed using the short notation

  5. Document / PI <?xml version=“1.0”?> Element FitnessCenter Element Member ancestors Element Phone Element Name Element FavoriteColor Element Phone preceding sibling following siblings Text 555-4321 Text Jeff Text lightgrey Text 555-1234 If we are currently at the Member's first phone element then: we can select all ancestors by: all preceding siblings by: all following siblings by: ancestor::* preceding-sibling::* following-sibling::* Which yields: Which yields: Which yields: Member Name Phone FitnessCenter FavoriteColor

  6. Document / PI <?xml version=“1.0”?> Element FitnessCenter descendants Element Member (the other Member elements) Element Phone Element Name Element FavoriteColor Element Phone Text 555-4321 Text Jeff Text lightgrey Text 555-1234 If we are currently at the FitnessCenter element then: we can select all descendants by: descendant::* Which yields: Member Name Phone, etc (see axis-example01)

  7. Axis • ancestor, preceding-sibling, following-sibling, and descendent each provide a different way of navigating the XML tree. • They are each called an axis

  8. List of Axis • ancestor: selects all ancestors • ancestor-or-self: selects the current node plus all its ancestors • attribute: selects all the attributes • child: selects all the children • descendant: selects all the descendants • descendant-or-self: selects the current node plus all its descendants • following: selects everything in the document that follows the current node • following-sibling: selects the siblings that follow • namespace: selects all the namespaces that are in scope • parent: selects the parent • preceding: selects everything in the document that precedes the current node • preceding-sibling: selects the siblings that precede • self: selects the current node (see axis-example02)

More Related