[thelist] XPATH woes

Steve Lewis nepolon at worlddomination.net
Wed May 12 15:22:51 CDT 2004

Chris Hayes wrote:

> Looking for plain English help for this issue.  I want to return a list of
> all the bob id's in the xml below.
> <bobtypes>
>     <bob id="1"></bob>
>     <bob id="2"></bob>
>     <bob id="3"></bob>
> </bobtypes>
> to return "1,2,3"

English for XPath to return the nodeset (1,2,3):

1) string the element node names between here and there together with 
a slash separator.
2) add a trailing slash
3) add an @ symbol to indicate you are looking for an attribute
4) add the name of the attribute you want to look for

XSL to return the nodeset
<xsl:value-of select="bobtypes/bob/@id"/>

XPath to return the nodeset

XSL to return the string "1 + 2 + 3" is less easy

<xsl:for-each select="bobtypes/bob[@id]"/>
   <xsl:if test="position() &gt; 1">
     <xsl:text> + </xsl:text>
   <xsl:value-of select="@id">

> Is there any XPATH to do this?  Do you have any really good XPATH links to
> teach a novice.

a) see above
b) no.  get a book.

Essential XML Quick Reference: A Programmer's Reference to XML, XPath, 
XSLT, XML Schema, SOAP, and More

by Aaron Skonnard and Martin Gudgin

buy it from your favorite book retailer.


More information about the thelist mailing list