Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/pipeline/stage
In directory sc8-pr-cvs1:/tmp/cvs-serv19716
Modified Files:
XpathExtractPipelineStage.java
Log Message:
Allow all types of XPath expressions, e.g. count() etc.
Index: XpathExtractPipelineStage.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/pipeline/stage/XpathExtractPipelineStage.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** XpathExtractPipelineStage.java 27 Jun 2003 02:19:59 -0000 1.8
--- XpathExtractPipelineStage.java 14 Jul 2003 17:27:16 -0000 1.9
***************
*** 75,78 ****
--- 75,79 ----
import org.apache.xpath.XPathAPI;
+ import org.apache.xpath.objects.XObject;
import org.w3c.dom.Document;
***************
*** 153,181 ****
serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
! NodeIterator nl = XPathAPI.selectNodeIterator(doc, xpath);
StringBuffer buffer = new StringBuffer();
- Node n;
int ctr = 0;
! while ((n = nl.nextNode()) != null) {
! if (isTextNode(n)) {
! // DOM may have more than one node corresponding to a
! // single XPath text node. Coalesce all contiguous text nodes
! // at this level
! buffer.append(n.getNodeValue());
!
! for (Node nn = n.getNextSibling(); isTextNode(nn);
! nn = nn.getNextSibling()) {
! buffer.append(nn.getNodeValue());
! }
! } else {
! ByteArrayOutputStream baos = new ByteArrayOutputStream();
! serializer.transform(new DOMSource(n), new StreamResult(baos));
! buffer.append(baos.toString());
! }
!
! ctr++;
}
!
if (ctr == 0) {
throw new PipelineException("Unable to find XPath Tag = " + xpath +
--- 154,189 ----
serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
! XObject xobj = XPathAPI.eval(doc, xpath);
!
StringBuffer buffer = new StringBuffer();
int ctr = 0;
! if (xobj.getType() == XObject.CLASS_NODESET) {
! NodeIterator nl = xobj.nodeset();
! Node n;
! while ((n = nl.nextNode()) != null) {
! if (isTextNode(n)) {
! // DOM may have more than one node corresponding to a
! // single XPath text node. Coalesce all contiguous text nodes
! // at this level
! buffer.append(n.getNodeValue());
!
! for (Node nn = n.getNextSibling(); isTextNode(nn);
! nn = nn.getNextSibling()) {
! buffer.append(nn.getNodeValue());
! }
! } else {
! ByteArrayOutputStream baos = new ByteArrayOutputStream();
! serializer.transform(new DOMSource(n), new StreamResult(baos));
! buffer.append(baos.toString());
! }
! ctr++;
! }
}
! else {
! ctr = 1;
! buffer.append(xobj.toString());
! }
!
if (ctr == 0) {
throw new PipelineException("Unable to find XPath Tag = " + xpath +
|