[XML4Lib] xpath expression

Reese, Terry terry.reese at oregonstate.edu
Fri Sep 21 12:55:35 EDT 2007


If I just needed to generically process the data in the c* nodes and was
doing this in xslt (or programmically where I could access items as an
array), I'd likely do something like the following simple xslt sheet.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="html" />
<xsl:template match="/ead/archdesc/dsc">
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="*[starts-with(name(), 'c')]">
	<blockquote>
		
		<xsl:text>Node Name: </xsl:text><xsl:value-of
select="name()" /><br />
		<xsl:apply-templates />
	</blockquote>
</xsl:template>
<xsl:template match="p">
  <blockquote>
	<xsl:value-of select = "." /><br />
  </blockquote>
</xsl:template>
<xsl:template match="text()" />
</xsl:stylesheet>

--TR 

> -----Original Message-----
> From: xml4lib-bounces at webjunction.org 
> [mailto:xml4lib-bounces at webjunction.org] On Behalf Of Eric 
> Lease Morgan
> Sent: Friday, September 21, 2007 8:35 AM
> To: xml4lib
> Subject: [XML4Lib] xpath expression
> 
> 
> 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*'>
> 
> --
> Eric "Needs A Better XPath Reference Book" Morgan
> 
> 
> _______________________________________________
> XML4Lib mailing list
> XML4Lib at webjunction.org
> http://lists.webjunction.org/mailman/listinfo/xml4lib
> 


More information about the XML4Lib mailing list