[XML4Lib] xpath expression

David Sewell dsewell at virginia.edu
Fri Sep 21 11:57:29 EDT 2007


If you are using something that supports XPath 2.0, this will retrieve
only elements named "c" or "c01" .. "c12":

   //*[matches(local-name(.), '^c(0\d|1[0-2])*$')]

With XPath 1.0 I think it's going to require

  <xsl:for-each select='//c|//c01|//c02|//c03'> etc.

explicitly naming each element.

On Fri, 21 Sep 2007, Eric Lease Morgan wrote:

>
> Can somebody here please tell me a secret XPath expression -- incantation -- I
> can use to list all of the elements matching c01 - c12 in the following XML
> snippet:
>
> <ead>
>  <eadheader />
>  <archdesc>
>    <dsc>
>      <!-- insert any number of c or c01 elements here, but not both -->
>      <c01>
>        <!-- insert any number of c02 elements here -->
>        <p>co1</p>
>        <c02>
>          <!-- insert any number of c03 elements here -->
>          <p>co2</p>
>          <c03>
>            <!-- insert any number of c04 through c12 elements here -->
>            <p>co3a</p>
>          </c03>
>          <c03>
>            <p>co3b</p>
>          </c03>
>          <c03>
>            <p>co3c</p>
>          </c03>
>        </c02>
>      </c01>
>    </dsc>
>  </archdesc>
> </ead>
>
> The XML snippet above represents an EAD file. Each EAD file can contain any
> number of "components" denoted by elements c or c01 through c12. Each of these
> components are often times folders in gray boxes on archive shelves.
>
> I want to get a list of all these components, read their child data, and index
> it. I suppose I could something like this:
>
>  <xsl:for-each select='//c01'>
>  </xsl:for-each>
>
> and the repeat it for all the other elements (c02 through c12, plus c), but
> that doesn't seem very efficient. There is probably a better way. Something
> list does not compile:
>
>  <xsl:for-each select='//c*'>
>
>

-- 
David Sewell, Editorial and Technical Manager
ROTUNDA, The University of Virginia Press
PO Box 801079, Charlottesville, VA 22904-4318 USA
Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
Email: dsewell at virginia.edu   Tel: +1 434 924 9973
Web: http://rotunda.upress.virginia.edu/


More information about the XML4Lib mailing list