public class SimpleXpathEngine extends java.lang.Object implements XpathEngine, XSLTConstants
copy-of
or value-of
XSL template (as
appropriate) to execute the Xpath.
This is not an efficient method for accessing XPaths but it is portable
across underlying transform implementations. (Yes I know Jaxen is too, but
this approach seemed to be the simplest thing that could possibly work...)Modifier and Type | Field and Description |
---|---|
private NamespaceContext |
ctx |
JAVA5_XSLTC_FACTORY_NAME, XSLT_END, XSLT_IDENTITY_TEMPLATE, XSLT_START, XSLT_START_NO_VERSION, XSLT_STRIP_COMMENTS_TEMPLATE, XSLT_STRIP_WHITESPACE, XSLT_XML_OUTPUT_NOINDENT
CLOSE_NODE, END_CDATA, END_COMMENT, END_PROCESSING_INSTRUCTION, NULL_NS_URI, OPEN_END_NODE, OPEN_START_NODE, START_CDATA, START_COMMENT, START_DOCTYPE, START_PROCESSING_INSTRUCTION, W3C_XML_SCHEMA_INSTANCE_NO_NAMESPACE_SCHEMA_LOCATION_ATTR, W3C_XML_SCHEMA_INSTANCE_NS_URI, W3C_XML_SCHEMA_INSTANCE_SCHEMA_LOCATION_ATTR, W3C_XML_SCHEMA_NS_URI, XML_DECLARATION, XMLNS_PREFIX, XPATH_ATTRIBUTE_IDENTIFIER, XPATH_CHARACTER_NODE_IDENTIFIER, XPATH_COMMENT_IDENTIFIER, XPATH_NODE_INDEX_END, XPATH_NODE_INDEX_START, XPATH_PROCESSING_INSTRUCTION_IDENTIFIER, XPATH_SEPARATOR
Constructor and Description |
---|
SimpleXpathEngine() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
evaluate(java.lang.String select,
org.w3c.dom.Document document)
Evaluate the result of executing the specified xpath syntax
select expression on the specified document |
private java.lang.String |
getCopyTransformation(java.lang.String select) |
org.w3c.dom.NodeList |
getMatchingNodes(java.lang.String select,
org.w3c.dom.Document document)
Execute the specified xpath syntax
select expression
on the specified document and return the list of nodes (could have
length zero) that match |
private java.lang.String |
getNamespaceDeclarations()
returns namespace declarations for all namespaces known to the
current context.
|
private java.lang.String |
getValueTransformation(java.lang.String select) |
protected org.w3c.dom.Document |
getXPathResultAsDocument(java.lang.String select,
org.w3c.dom.Document document)
Execute the copy-of transform and return the resulting Document.
|
protected org.w3c.dom.Node |
getXPathResultNode(java.lang.String select,
org.w3c.dom.Document document)
Testable method to execute the copy-of transform and return the root
node of the resulting Document.
|
private java.lang.StringBuilder |
getXSLTBase()
What every XSL transform needs
|
private void |
performTransform(java.lang.String xslt,
org.w3c.dom.Document document,
javax.xml.transform.Result result)
Perform the actual transformation work required
|
void |
setNamespaceContext(NamespaceContext ctx)
Establish a namespace context.
|
private NamespaceContext ctx
private java.lang.StringBuilder getXSLTBase()
private java.lang.String getCopyTransformation(java.lang.String select)
select
- an xpath syntax select
expressioncopy-of
transformationprivate java.lang.String getValueTransformation(java.lang.String select)
select
- an xpath syntax select
expressionvalue-of
transformationprivate void performTransform(java.lang.String xslt, org.w3c.dom.Document document, javax.xml.transform.Result result) throws javax.xml.transform.TransformerException, ConfigurationException, XpathException
xslt
- document
- result
- XpathException
javax.xml.transform.TransformerException
ConfigurationException
protected org.w3c.dom.Node getXPathResultNode(java.lang.String select, org.w3c.dom.Document document) throws ConfigurationException, javax.xml.transform.TransformerException, XpathException
select
- document
- ConfigurationException
javax.xml.transform.TransformerException
XpathException
protected org.w3c.dom.Document getXPathResultAsDocument(java.lang.String select, org.w3c.dom.Document document) throws ConfigurationException, javax.xml.transform.TransformerException, XpathException
select
- document
- ConfigurationException
javax.xml.transform.TransformerException
XpathException
public org.w3c.dom.NodeList getMatchingNodes(java.lang.String select, org.w3c.dom.Document document) throws ConfigurationException, XpathException
select
expression
on the specified document and return the list of nodes (could have
length zero) that matchgetMatchingNodes
in interface XpathEngine
select
- document
- ConfigurationException
XpathException
public java.lang.String evaluate(java.lang.String select, org.w3c.dom.Document document) throws ConfigurationException, XpathException
select
expression on the specified documentevaluate
in interface XpathEngine
select
- document
- ConfigurationException
XpathException
public void setNamespaceContext(NamespaceContext ctx)
XpathEngine
setNamespaceContext
in interface XpathEngine
private java.lang.String getNamespaceDeclarations()