Class XPathNormalizer
- All Implemented Interfaces:
Rewriter<DOMResource,XPathRefinedByRFC5147CharScheme, XPathRefinedByRFC5147CharScheme>
- Direct Known Subclasses:
XPathNormalizerWithXPath
DOMResource can be
selected by different pairs of XPaths and RFC 5147 character
schemes (or range schemes), i.e. *referentially equal* selectors
may have different values. Normalization maps referentially equal
selectors to the same selector. This XPathNormalizer is a
base class for such normalization tasks.Normalization of selectors is a 2-stage process: 1) In the first stage, the text position (or range) which is referenced by the selector, has to be found. A pair containing a text node and an RFC 5147 character scheme position is returned. 2) In the second stage, this position is expressed as a selector again, i.e., the node is referenced with an XPath, where the XPath may be written as a path expression descending from the root element, or from the deepest element with an XML-ID, etc., and even the character scheme component of the selector may be recalculated.
There is **not** the one and only normalization. Both stages of the normalization process may be implemented differently, leading to different results. For corner cases, even the first stage may lead to different results.
This class implements the first stage of the normalization
process. The algorithm is selected by values of the Mode
enum type, which is passed to the normalization methods. The second
stage of the normalization process has to be implemented by
subclasses of the abstract base class.
XPath expressions to be normalized may be arbitrary XPath 4.0
expressions which select a single node from the
DOMResource. Expressions selecting not exactly one node
result in an SelectorException.
-
Nested Class Summary
Nested classes/interfaces inherited from interface de.wwu.scdh.annotation.selection.Rewriter
Rewriter.Direction -
Field Summary
Fields inherited from class de.wwu.scdh.annotation.selection.rewriter.XPathRewriterBase
EMPTY_NAMESPACE, TEXT_LEAF, TRACE_TEXT_LEAF, xpath, xPathCompiler -
Constructor Summary
ConstructorsConstructorDescriptionXPathNormalizer(net.sf.saxon.s9api.XPathCompiler xPathCompiler, String xpath) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract StringgetNormalizedXPath(DOMResource resource, net.sf.saxon.s9api.XdmNode node, boolean escaped) This abstract method must be implemented by normalizers.rewrite(DOMResource resource, XPathRefinedByRFC5147CharScheme point, RewriterConfig config) Normalize an XPath Selector refined by an RFC5147 character scheme.Methods inherited from class de.wwu.scdh.annotation.selection.rewriter.XPathRewriterBase
getDeepTextNodeAtPositionStepOverEnd, getDeepTextNodeAtPositionStopAtEnd, getDepth, getDepth, getDescendantTextNodesWithPosition, getFirstNodeAtPosition, getFirstOfDeepestNodesAtPosition, getLastOfDeepestNodesAtPosition, getNode, getNode, getNode, getSecondNodeAtPosition, getTextNodeAtPosition, getTextNodesWithPosition, getXPath, pathExpressionWithXPath, posInNormalizedNode, postProcForwardPaths, replaceEmptyNamespace, replaceTextLeaf, replaceTextLeaf, replaceTraceTextLeaf, reportNotFound, unespace
-
Constructor Details
-
XPathNormalizer
-
-
Method Details
-
rewrite
public List<XPathRefinedByRFC5147CharScheme> rewrite(DOMResource resource, XPathRefinedByRFC5147CharScheme point, RewriterConfig config) throws SelectorException Normalize an XPath Selector refined by an RFC5147 character scheme. The position must be a valid character position *inside* the fragment selected by the XPath expression. If the fragment's text (its concatenated text nodes) is shorter than the position's value, aSelectorExceptionis thrown.In general, this method will result in a recalculated XPath *and* position.
- Specified by:
rewritein interfaceRewriter<DOMResource,XPathRefinedByRFC5147CharScheme, XPathRefinedByRFC5147CharScheme> - Parameters:
resource- theDOMResourceon the base of which the normalization is donepoint- anXPathRefinedByRFC5147CharSchemerecord representing point in the resourceconfig- a record with configuration options- Returns:
- a recalculated
XPathRefinedByRFC5147CharScheme - Throws:
SelectorException- when the position cannot be found in the resource //
-
getNormalizedXPath
protected abstract String getNormalizedXPath(DOMResource resource, net.sf.saxon.s9api.XdmNode node, boolean escaped) throws SelectorException This abstract method must be implemented by normalizers. It returns the normalized path to the node given as argument.- Parameters:
node- anXdmNodeto which the normalized path must be generated toescaped- whether or not the normalized XPath is to be escaped for X-processing, e.g.,'escaped to'.- Returns:
- the normalized XPath expression as a String
- Throws:
SelectorException- See Also:
-