Subject: RE: [xsl] XPath problem From: "David P. Nesbitt" <david_p_nesbitt@xxxxxxxxx> Date: Thu, 27 Jan 2005 15:15:32 -0800 (PST) |
Michael and Jarno, Thanks always for your excellent assistance. XSLT adoption is facilitated by your kind expertise on this mailing list. The '<=' problem was solved with '<='. Thanks for catching that. I still have the "*" problem though. It does not seem to find the Node when the XPath utilizes the asterisk. It may be a DOM4J issue, but before going there I thought I would check with you folks first. I am including a small, standalone Java test program that demostrates this problem. The XML document is a static String in the source file. Please let me know if you see any problems with it. Here is what I get when I run the program: C:\>java -cp .;dom4j.jar;xercesImpl.jar;xml-apis.jar;jaxen.jar Test toDate = FAIL Regards, Dave import java.util.HashMap; import java.util.Map; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Node; import org.dom4j.XPath; public class Test { private static final Map NAMESPACE_URIS = new HashMap(); static { NAMESPACE_URIS.put("rr", "http://www.mwvis.com/interfaces/ReportRequest.xsd"); NAMESPACE_URIS.put("xqx", "http://www.w3.org/2003/12/XQueryX"); NAMESPACE_URIS.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); } private static final String REQUEST_DOCUMENT = "<rr:ReportRequest name=\"MisplacedItemsHistory\"" + " xmlns:rr=\"http://www.mwvis.com/interfaces/ReportRequest.xsd\"" + " xmlns:xqx=\"http://www.w3.org/2003/12/XQueryX\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + " <rr:Specification responseType=\"Xml\" returnTotalRecords=\"true\">" + " <rr:CountPerPage>20</rr:CountPerPage>" + " <rr:Page>4</rr:Page>" + " <rr:UserId>6</rr:UserId>" + " </rr:Specification>" + " <xqx:whereClause>" + " <xqx:expr xsi:type=\"operatorExpr\" infix=\"true\">" + " <xqx:opType>and</xqx:opType>" + " <xqx:parameters>" + " <xqx:expr xsi:type=\"operatorExpr\" infix=\"true\">" + " <xqx:opType>>=</xqx:opType>" + " <xqx:parameters>" + " <xqx:expr xsi:type=\"stringConstantExpr\">" + " <xqx:value>DateMisplaced</xqx:value>" + " </xqx:expr>" + " <xqx:expr xsi:type=\"stringConstantExpr\">" + " <xqx:value>2004-06-01 00:00:00.000000</xqx:value>" + " </xqx:expr>" + " </xqx:parameters>" + " </xqx:expr>" + " <xqx:expr xsi:type=\"operatorExpr\" infix=\"true\">" + " <xqx:opType><=</xqx:opType>" + " <xqx:parameters>" + " <xqx:expr xsi:type=\"stringConstantExpr\">" + " <xqx:value>DateMisplaced</xqx:value>" + " </xqx:expr>" + " <xqx:expr xsi:type=\"stringConstantExpr\">" + " <xqx:value>2004-07-01 00:00:00.000000</xqx:value>" + " </xqx:expr>" + " </xqx:parameters>" + " </xqx:expr>" + " </xqx:parameters>" + " </xqx:expr>" + " </xqx:whereClause>" + "</rr:ReportRequest>"; private static final String XPATH_TO_DATE_NODE = "/rr:ReportRequest/xqx:whereClause/*/xqx:expr[" + "@xsi:type = 'operatorExpr' " + "and xqx:opType = '<=' " + "and xqx:parameters/xqx:expr[1]/xqx:value = 'DateMisplaced']" + "/xqx:parameters/xqx:expr[2]/xqx:value"; public static void main(String[] args) { try { Document requestDoc = DocumentHelper.parseText(REQUEST_DOCUMENT); String toDate = getToDate(requestDoc); System.out.println("toDate = " + toDate); } catch (Exception e) { e.printStackTrace(System.out); } } /* main */ private static String getToDate(Document requestDoc) { Node toDateNode = null; XPath xpath = null; xpath = requestDoc.createXPath(XPATH_TO_DATE_NODE); xpath.setNamespaceURIs(NAMESPACE_URIS); toDateNode = xpath.selectSingleNode(requestDoc); return (null == toDateNode) ? "FAIL" : toDateNode.getText(); } /* getToDate */ } /* Test */ --- Michael Kay <mike@xxxxxxxxxxxx> wrote: > > > > The second problem is that it does not like: > > > > xqx:opType = '<=' > > > > Is there a problem with this? The element text > > contains the string "<=". But the match does > not > > work. > > > > < is converted to < by an XML parser. Your source > document has been > parsed and this conversion has been done. But since > you are submitting the > XPath expression to DOM4J from a Java application, > the XPath expression > doesn't go through an XML parser, so it isn't > converted to <. Write > xqx:opType = '<='. > > Michael Kay > http://www.saxonica.com/ > > __________________________________ Do you Yahoo!? Yahoo! Mail - Find what you need with new enhanced search. http://info.mail.yahoo.com/mail_250
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XPath problem, Michael Kay | Thread | AW: [xsl] struggling with <xsl:anal, Huditsch Roman |
RE: [xsl] Fw: JAXP 1.3 with Saxon, Michael Kay | Date | Re: [xsl] Disable output-escaping, David Carlisle |
Month |