Hello,

I'm facing a problem when using dom4j's XSLT rule api when the source
document contains elements in the default namespace.
I've read the posting 'Problem with selectSingleNode() when xml tree
contains xmlns attribute' and know about the solution to set an appropriate
namespace context to the XPath instance. 

Considering the sample XML listed below the following xpath expression works
well and returns the <package> element.

//sample xpath with namespace context
HashMap map = new HashMap();
map.put("cdl", "http://www.w3.org/2005/10/cdl";);
XPath xpath = DocumentHelper.createXPath("cdl:package");
xpath.setNamespaceContext(new SimpleNamespaceContext(map));
List list = xpath.selectNodes(xpath);

However, I don't see any possibility to provide such namespace context
information when using the rule api. 
It's no surprise that the below listed sample rule only invokes it's action
if the element <package> does not contain the xmlns="..." NS declaration.
The problem is, that DocumentHelper.createPattern only accepts a string
containing an xpath-expression. I could not find any way to provide an XPath
instance (with appropriate namespace context).

Does anyone have an idea how to get the rule api working if default
namespace comes into play? In general, the rule api is very powerful - it
would be a pitty if this circumstance restricts its use.

Brgds,
Christian


//sample rule
Rule rule1 = new Rule();      
rule1.setPattern( DocumentHelper.createPattern( "package" ) );
rule1.setAction( new action1 ());
style = new Stylesheet();
style.addRule( rule1 );
style.run( xmldoc );


//sample XML
<package xmlns="http://www.w3.org/2005/10/cdl";>
 <choreography>
  <sequence>...</sequence>
 </choreography>
</package>
  





-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to