Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
Xalan XPathAPI question
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Adam Jenkins, post: 553240"] Can you give an example of why you want to be able to use XPath variables instead of just substiting in literals from Java? The reason XPath has support for variables is because it was originally designed to be embedded inside XSLT documents. In order for XPath expressions to be able to interact with the XSLT document, XSLT has the ability to define variables, which can be accessed from XPath expressions. So in XSLT you can define a variable: <xsl:variable name="var">value</xsl:variable> And later use the variable in an XPath expression: <xsl:value-of select="/document/element[name=$var]"/> When using XPath from Java instead from XSLT, the equivalent would be String var = "value"; XPathAPI.selectSingleNode(doc, "/document/element[name=' " + var + "']"); There isn't really any need for the XPath variables when using XPath from Java since Java already has variables of its own. I suppose it could be nice to have something like PreparedStatement in the java.sql API where you don't always have to explicitly concatenate strings. In that case you could use a java.text.MessageFormat object, as in: Format xpathFormat = new MessageFormat("/document/element[name='{0}']"); String var = "value"; String xpath = xpathFormat.format(new Object[]{var}); Use a different value: var = "another value"; xpath = xpathFormat.format(new Object[]{var}); [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Xalan XPathAPI question
Top