To solve this problem I've modified dom4j semantics with respect to
attributes with null values.
Adding an attribute with a null value is now equivalent to removing it. This
means that when a dom4j document gets passed to other XML engines like XSLT
or other DOM or SAX providers, no null valued attributes will be passed
through.
The following pseduo code demonstates the new behaviour in action. For a
more concrete display of the new semantics the JUnit test case
dom4j/src/test/org/dom4j/TestNullAttributes.java shows the new behaviour
explicitly.
Element element = ...;
element.addAttribute( "foo", "123" );
...
Attribute attribute = element.attribute( "foo" );
assertTrue( attribute != null );
...
element.addAttribute( "foo", null );
attribute = element.attribute( "foo" );
assertTrue( attribute == null );
This behaviour is now in CVS and the daily build which should fix any
null-valued-attribute related problems.
James
----- Original Message -----
From: David Frankson
To: [EMAIL PROTECTED]
Sent: Saturday, April 06, 2002 5:25 AM
Subject: [dom4j-user] XSL Saxon, dom4j and NullpointerExceptions
I have a large Xerces DOM + Saxon XSL web application that is working
smoothly. I'm considering porting it to dom4j for the cleaner dom and xpath
java API.
Several places in a few different xsl documents, I'm getting null pointer
exceptions during processing. I've narrowed it down to the following
statement:
<SELECT name="hearingStatus">
<OPTION/>
<xsl:element name="OPTION">
<xsl:attribute name="value">pass</xsl:attribute>
<xsl:if
test="$screen[@screeningID=$ID]/hearing/@status='pass'"><xsl:attribute
name="selected"/></xsl:if>
pass
</xsl:element>
</SELECT>
Its kind-a odd, but I think it has something to do with a xsl:if inside an
element when the xsl:if has a "" as part of the test expression. The
$screen/@screeningID attribute does exist as a node, but its value is an
empty string. I have tried it with the full xpath instead of the global
variable, and I get the same exception. I have tried the same xsl:if
statement outside the xsl:element and everything works as expected.
Any ideas on where next to look for a solution? Since this works fine with
Saxon and Xerces, I figured it has something to do with dom4j's Document
implementation.
Stack trace below:
java.lang.NullPointerException
at
com.icl.saxon.expr.NodeSetComparison.evaluateAsBoolean(NodeSetComparison.jav
a:66)
at com.icl.saxon.style.XSLIf.process(XSLIf.java:77)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at com.icl.saxon.style.XSLElement.process(XSLElement.java:139)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at com.icl.saxon.style.XSLTemplate.expand(XSLTemplate.java:225)
at com.icl.saxon.style.XSLCallTemplate.process(XSLCallTemplate.java:187)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at
com.icl.saxon.style.LiteralResultElement.process(LiteralResultElement.java:2
88)
at com.icl.saxon.style.StyleElement.processChildren(StyleElement.java:633)
at com.icl.saxon.style.XSLTemplate.expand(XSLTemplate.java:225)
at com.icl.saxon.style.XSLTemplate.start(XSLTemplate.java:198)
at com.icl.saxon.Controller.applyTemplates(Controller.java:254)
at com.icl.saxon.Controller.defaultAction(Controller.java:270)
at com.icl.saxon.Controller.applyTemplates(Controller.java:235)
at com.icl.saxon.Controller.run(Controller.java:177)
at com.icl.saxon.Controller.transformDocument(Controller.java:1075)
at com.icl.saxon.Controller.transform(Controller.java:945)
at com.infinitecampus.prism.Prism.service(Prism.java:266)
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user