}
// strip off the %{ } so that we are left with the xpath
String expressionStr =
PipelineExpressionHelper.removePipelineQuoting(
value, exprPrefixes, exprSuffixes);
XMLPipelineContext pipelineContext = getPipelineContext();
try {
// parse the xpath
Expression expression = parser.parse(expressionStr);
// obtain the ExpressionContext from the PipelineContext
// the ExpressionContext is needed in order to evaluate the
// expression parsed
ExpressionContext expressionContext =
getPipelineContext().getExpressionContext();
// evaluate the experssion
Value result = expression.evaluate(expressionContext);
if (result.getSequence().getLength() == 0) {
// if the sequence is empty then we must remove the
// attriubute.
output.removeAttribute(i);
} else {
// update the current attribute with the string
// representation of the evaluated expression.
output.setValue(i, result.stringValue().asJavaString());
}
}
catch (Exception e) {
// something went wrong when evaluating the xpath.
// Send an error down the pipeline
Locator locator = pipelineContext.getCurrentLocator();
XMLPipelineException se = new XMLPipelineException(
"Could not evaluate the expression " +
expressionStr,
locator,
e);