[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: XPath problem

Subject: RE: XPath problem
From: "Sanjay Pandey/Towers Perrin" <pandeys@xxxxxxxxxx>
Date: Thu, 20 Dec 2001 09:51:21 -0500
xpathapi eval attribute

Mike,

I am using Xalan.

Also, I am writing as "/*[name()='type']" as in the actual application I
have some other attribute checks too "/*[name()='type' or name() = 'name'
...]"

Thanks,


                                                                                                                                
                                                                                                                                
                                                      To:     <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>                                 
                    "Michael Kay"                     cc:     (bcc: Sanjay Pandey/Towers Perrin)                                
                    <michael.h.kay@xxxxxxxxxxxx       Subject:     RE:  XPath problem                                      
                    >                                                                                                           
                    Sent by:                                                                                                    
                    owner-xsl-list@xxxxxxxxxxxx                                                                                 
                    rytech.com                                                                                                  
                                                                                                                                
                                                                                                                                
                    12/20/2001 09:16 AM                                                                                         
                    Please respond to xsl-list                                                                                  
                                                                                                                                
                                                                                                                                




> I have my XML as follows
>
> <records>
>      <record1 type="type1">
>           <field1 value="xyz">
>      </record1>
>
>      <record1 type = "type2">
>      </record1>
> </records>
>
> If I am looking for an element which does not happen to be an
> attribute my
> logic below works fine in getting the nearest "@type" value
> on the ancestor
> axis.
>
> NodeList nl = XPathAPI.eval(root,
> //xs:field1,prefixResolver).nodelist()
> and then for each Node instance I can get the nearest "@type" value by
> doing something like this

There are quite a few XPath APIs around now that are confusingly similar,
it
would help if you told us which one you were using.
>
>  XObject obj = XPathAPI.eval(currentRecord1Node,"ancestor::
> *[@type][1]/@*[name()='type']",prefixResolver);

Why do you write "/*[name()='type']" rather than "/@type"?

>  String result = obj.toString();
>
> I run into problem when what I am looking happens to be an
> Attribute e,g
> "value". So, if my "currentRecord1Node" is for this attribute element
> "value", I am loosing my Node structure information and I am
> unable to get
> to the nearest "@type" value.

Your terminology is way out (there is no such thing as an attribute
element,
I think you mean an attribute node). But I can't see any reason why the
above expression shouldn't work just because the current node is an
attribute: attributes have ancestors jsut as elements do.

Mike Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list






 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.