Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XPath Developer's Guide

Using Abbreviations in XPath Expressions

Several shortcuts are available to be used in place of certain axes:

The first selects all <name> elements which are children of the context node; the second, all <name> elements which are children of the root node, that is, it selects an empty node-set, since the root node's only child is the <chairman> element.

Example

This example doesn't generate significant output. It demonstrates that no errors are generated by the above XPath expressions.

XML File (booksxpath.xml)

Use the orgchart.xml (in Sample XML File for Navigating XPath Axes) and change its href attribute to point to xpabbr.xsl.

XSLT File (xpabbr.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- suppress text nodes not covered in subsequent template rule -->
<xsl:template match="text()"/>

<xsl:template match="president">
   <p/>child::name -- 
      <xsl:value-of select='child::name'/>
   <p/>name -- 
      <xsl:value-of select='name'/>
   <p/>director/attribute::empdate -- 
      <xsl:value-of select='director/attribute::empdate'/>
   <p/>ddirector/@empdate -- 
      <xsl:value-of select='ddirector/@empdate'/>
   <p/>name[.="Kim Akers"]/descendant-or-self::node()/name -- 
      <xsl:value-of select='name[.="Kim Akers"]/descendant-or-self::node()/name'/>
   <p/>name[.="Kim Akers"]//name -- 
      <xsl:value-of select='name[.="Kim Akers"]//name'/>
   <p/>self::node()/attribute::empdate -- 
      <xsl:value-of select='self::node()/attribute::empdate'/>
   <p/>./attribute::empdate -- 
      <xsl:value-of select='./attribute::empdate'/>
   <p/>./@empdate -- 
      <xsl:value-of select='./@empdate'/>
   <p/>parent::node()[self::node()="Josh Barnett"] -- 
      <xsl:value-of select='parent::node()[self::node()="Josh Barnett"]'/>
   <p/>..[self::node()="Josh Barnett"] -- 
      <xsl:value-of select='..[self::node()="Josh Barnett"]'/>
   <p/>..[.="Josh Barnett"] -- 
      <xsl:value-of select='..[.="Josh Barnett"]'/>
   <p/>attribute::empID | attribute::empdate -- 
      <xsl:value-of select='attribute::empID | attribute::empdate'/>
   <p/>attribute::* -- 
      <xsl:value-of select='attribute::*'/>
   <p/>@* -- 
      <xsl:value-of select='@*'/>
   <p/>name -- 
      <xsl:value-of select='name'/>
   <p/>/name -- 
      <xsl:value-of select='/name'/>
</xsl:template>

</xsl:stylesheet>

See Also

Sample XML File for Navigating XPath Axes