XSLTResut.exposedValue transform failing on CDATA elements
----------------------------------------------------------

                 Key: WW-2234
                 URL: https://issues.apache.org/struts/browse/WW-2234
             Project: Struts 2
          Issue Type: Bug
    Affects Versions: 2.0.9
         Environment: Tomcat 6.0.14
Struts 2.0.9
JDK 1.5.0_11
Xalan 2.7.0
            Reporter: Stewart Witchalls
            Priority: Minor


Xalan 2.7.0 (with bundled Xerces) installed into $JDK_HOME/jre/lib/endorsed and 
$TOMCAT_HOME/common/endorsed

action config:
        <action name="ShowDataFormDemo" class="ShowDataFormDemo">
            <result type="xslt">
                <param name="location">/WEB-INF/xsl/CreateDataForm.xsl</param>
                <param name="exposedValue">presenterXml</param>
            </result>
        </action>

ShowDataFormDemo.presenterXml code:
  public org.w3c.dom.Document getPresenterXml() throws Exception
  {
        final byte[] data = this.presenterXml.getBytes("UTF-8");
        final DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance();
        final Document doc2 = factory.newDocumentBuilder().parse( new 
ByteArrayInputStream(data) );

        // debug to see if XPATH works inside server
        final XPathFactory fact = XPathFactory.newInstance();
        final XPath xpath = fact.newXPath();
        final XPathExpression xexpr = xpath.compile( "count(//items/*)" );
        System.out.println( xexpr.evaluate( doc2.getDocumentElement(), 
XPathConstants.NUMBER ) );

        return doc2;
  }

XML:
<data>
<items>
<heading inline="true">
<text><![CDATA[Data form example]]></text></heading>
<paragraph inline="true">
<text><![CDATA[Some explanatory text.]]></text></paragraph>
<subHeading inline="true">
<text><![CDATA[Lists]]></text></subHeading>
</items>
</data>

CreateDataForm.xsl fragment:
    vendor = <xsl:value-of select="system-property('xsl:vendor')"/>
    vendor-url = <xsl:value-of select="system-property('xsl:vendor-url')"/>
    xslt-version = <xsl:value-of select="system-property('xsl:version')"/>
    count(items) = <xsl:value-of select="count(//items/*)"/>


XPath in code works and returns correct count (aka. 3).

However, same xpath in CreateDataForm.xsl transform fails and only returns 1. 
Also, transform not able to obtain CDATA values (ie. displays nothing when 
"text" element selected).

I've removed + added rows to the XML. The CreateDataForm.xsl transform always 
says count = "1". It looks like it cannot see past the first CDATA section.

If I remove the CDATA sections (ie. encode the element data as XML encoded 
strings), transform xpath works??!!

I've checked classpaths and can confirm that the endorsed Xalan libraries are 
being picked up.

I've even run the transform inside the action itself. It worked as expected.

I can work around this by removing the CDATA sections from the XML, but I've 
spent the last few days going mad. Just cannot see what's going wrong.



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to