Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XPath expression and xsl:when

Reply
Thread Tools

XPath expression and xsl:when

 
 
gimme_this_gimme_that@yahoo.com
Guest
Posts: n/a
 
      04-26-2005

What xpath expression would return the category-item having uid sps002
?


<category-list>
<category>
<uid>GRIDS_MAIN_CATEGORY_UID</uid>
<uid-type>Categories</uid-type>
<category-item-list>
<category-item>
<uid>sps0002</uid>
<uid-type>Grids</uid-type>
</category-item>
<category-item>
<uid>sps0005style0003</uid>
<uid-type>Grids</uid-type>
</category-item>
</category>
<category>
<uid>GRIDS_MAIN_CATEGORY_UID</uid>
<uid-type>Categories</uid-type>
<category-item-list>
<category-item>
<uid>sps0002</uid>
<uid-type>Grids</uid-type>
</category-item>
<category-item>
<uid>sps0005style0003</uid>
<uid-type>Grids</uid-type>
</category-item>
</category>
</category-list>

I've tried the following Xpath expression ... :

<xsl:when
test="'sps0002'=//category-list/category/category-item-list/category-item/uid">
<xsl:value-of select="./uid"/>

Which doesn't work. (Help!)

But actually, what I'd really like is an Xpath expression
that would fetch this node directly without using a xsl:when.

What I'm actually doing is checking if a node with an id of sps002
exists in a JDOM Element using it's the JDOM XPath object. This returns
either an Element or an Attribute. But right now I'm having to
fetch all the category-item Elements and iterate through them to
determine
if one with an sps002 id exists.

Thanks.

 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      04-26-2005

> What xpath expression would return the category-item having uid sps002


/category-list/category/category-item-list/category-item[uid='sps2002']

<xsl:when
test="'sps0002'=//category-list/category/category-item-list/category-item/uid">


That tests if there us any uid anywhere in the document that has this
value, so it will be always true or always false depending on whether
such a node exists.

<xsl:value-of select="./uid"/>

so this will select the uid child of the current node whether or not
this is the node taht has the specified uid.

David
 
Reply With Quote
 
 
 
 
gimme_this_gimme_that@yahoo.com
Guest
Posts: n/a
 
      04-26-2005
Man .. The people on this list are *so* helpful. Thanks.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments