Here is a fragment from Xalan-J documentation.
// Instantiate an XPathFactory.
javax.xml.xpath.XPathFactory factory =
javax.xml.xpath.XPathFactory.newInstance();
// Use the XPathFactory to create a new XPath object
javax.xml.xpath.XPath xpath = factory.newXPath();
[1] // Compile an XPath string into an XPathExpression
javax.xml.xpath.XPathExpression expression = xpath.compile("/doc/name");
in step [1], you can construct string value of the XPath expression
programmatically, and can achieve what you described.
On 7/16/08, Adam Jenkins <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I was looking at the org.apache.xpath stuff, which is great for if you have
> an expression you need to evaluate...but I was wondering if there was a way
> to use Xalan to create an xpath expression programatically? For example:
>
> XPath path = new XPath();
> XPathStep step = new XPathStep();
> step.setAxis(...);
> step.setNodeText(...);
> step.setPredicate(...);
> path.addStep(step);
> ...continue for lots of steps...
>
> System.out.println("Xpath is: " + path.toString());
>
> Now obviously the above method calls are ficticious, I use them as an example
> to get across what I want to do. It would not be difficult for me to write
> some classes to do this, however I just thought I'd check if the ability
> already exists in Xalan first. Anyone have any ideas?
>
> Thanks
> Adam
--
Regards,
Mukul Gandhi