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

RE: XPath against a Document

Subject: RE: XPath against a Document
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Wed, 16 Feb 2000 09:56:17 -0000
xmlparserliaison
Just for comparison, in case anyone is interested, here's the equivalent in
Saxon:

public static final NodeSetValue getNodesByXPath(NodeInfo baseNode, String
sPath)
throws SAXException {
	Expression exp = Expression.make(sPath);
	Context c = new Context();
	c.setCurrent(baseNode);
	c.setPosition(1);
	c.setLast(1);
	return (NodeSetValue)exp.evaluate(c);
}

If the expression uses variables or namespace prefixes (not to mention keys
or decimal formats) you need to do a bit more work in setting up the
context.

Mike Kay

> -----Original Message-----
> From: Timm, Sean [mailto:STimm@xxxxxxxxxx]
> Sent: 15 February 2000 21:44
> To: 'xsl-list@xxxxxxxxxxxxxxxx'
> Subject: RE: XPath against a Document
> 
> 
>     /**
>      * This method searches for a specific set of nodes based 
> on the XPath
>      * statement passed into it.
>      * 
>      * @param baseNode Base node to process XPath statement against
>      * @param sPath XPath statement to execute against baseNode
>      * @return NodeList NodeList populated by nodes that match XPath
> expression
>      */
>     public static final NodeList getNodesByXPath(Node baseNode, String
> sPath)
>         throws Exception
>     {
>         String parserLiaisonClassName = Constants.LIAISON_CLASS;
>         Class parserLiaisonClass = 
> Class.forName(parserLiaisonClassName);
>         Constructor parserLiaisonCtor =
> parserLiaisonClass.getConstructor(null);
>         XMLParserLiaison parserLiaison
>         = (XMLParserLiaison)parserLiaisonCtor.newInstance(null);     
> 
>         // Create a XPath parser.
>         XPathProcessorImpl parser = new XPathProcessorImpl();
>               
>         // Create the XPath object.
>         XPath xpath = new XPath();
>               
>         // Parse the xpath
>         parser.initXPath(xpath, sPath, null);
>         XObject xobj = xpath.execute(parserLiaison, baseNode, null);
> 
>         return xobj.nodeset();
>     }
> 
> - Sean T.
> 
> -----Original Message-----
> From: Ben Bertola [mailto:bbertola@xxxxxxxxxxxx]
> Sent: Tuesday, February 15, 2000 3:49 PM
> To: xsl-list@xxxxxxxxxxxxxxxx
> Subject: Re: XPath against a Document
> 
> 
> I have this same question, this would be great to know if 
> it's possible.
> Thanks,
> Ben
> 
> 
> Paul Levin wrote:
> 
> > Using Xerces and Xalan;
> >     given a Document (i.e. DocumentImpl) and given a String 
> containing
> > an XPath expression, I would like to apply the expression 
> against the
> > document to obtain the NodeList that matchs the expression.  Is this
> > possible ?
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 
>  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.