XSLT

C

cameron

I have a method that contains the following:

--------------8<------ CODE ------>8--------------

Document XSL_XML =
XMLUtility.XMLDocument(sc.getRealPath("/XSLT/DirContents.xslt"));

DOMSource XML = new DOMSource(DirXML);
DOMSource XSL = new DOMSource(XSL_XML);
//return(XMLUtility.XMLToString(XSL_XML, true, 4));
StreamResult theTransformationResult = new StreamResult( new
ByteArrayOutputStream() );

Transformer theTransformer =
TransformerFactory.newInstance().newTransformer( XSL );
theTransformer.setOutputProperty(
"{http://xml.apache.org/xslt}indent-amount", "4" );
theTransformer.transform( XML,
theTransformationResult );

return theTransformationResult.getOutputStream().toString();

--------------8<------ CODE ------>8--------------

It keeps blowing up with a:

javax.xml.transform.TransformerException:
javax.xml.transform.TransformerException: stylesheet
requires attribute: version

but the XML document that is the stylesheet is good:

--------------8<------ CODE ------>8--------------

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:eek:utput method="html" indent="yes"/>

<xsl:param name="ShowDirs" value="no"/>
<xsl:param name="ShowImgs" value="no"/>

<xsl:template match="/Directory">
<xsl:for-each select="Entry">
<xsl:value-of select="@Filename"/><br/>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

--------------8<------ CODE ------>8--------------

(the commented out return shows the XML is as expected),and
contains the version attribute. I haven't been able to
serialize the DOMSource to check to see if the XML is in
there as expected.

Does anyone see what I am missing?

Thanks

-Cam
 
A

Anton Spaans

cameron said:
I have a method that contains the following:

--------------8<------ CODE ------>8--------------

Document XSL_XML =
XMLUtility.XMLDocument(sc.getRealPath("/XSLT/DirContents.xslt"));

DOMSource XML = new DOMSource(DirXML);
DOMSource XSL = new DOMSource(XSL_XML);
//return(XMLUtility.XMLToString(XSL_XML, true, 4));
StreamResult theTransformationResult = new StreamResult( new
ByteArrayOutputStream() );

Transformer theTransformer =
TransformerFactory.newInstance().newTransformer( XSL );
theTransformer.setOutputProperty(
"{http://xml.apache.org/xslt}indent-amount", "4" );
theTransformer.transform( XML,
theTransformationResult );

return theTransformationResult.getOutputStream().toString();

--------------8<------ CODE ------>8--------------

It keeps blowing up with a:

javax.xml.transform.TransformerException:
javax.xml.transform.TransformerException: stylesheet
requires attribute: version

but the XML document that is the stylesheet is good:

--------------8<------ CODE ------>8--------------

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:eek:utput method="html" indent="yes"/>

<xsl:param name="ShowDirs" value="no"/>
<xsl:param name="ShowImgs" value="no"/>

<xsl:template match="/Directory">
<xsl:for-each select="Entry">
<xsl:value-of select="@Filename"/><br/>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

--------------8<------ CODE ------>8--------------

(the commented out return shows the XML is as expected),and
contains the version attribute. I haven't been able to
serialize the DOMSource to check to see if the XML is in
there as expected.

Does anyone see what I am missing?

Thanks

-Cam
This looks good to me too (the only thing that I have extra in my stylesheet
is the encoding attribute, <?xml version="1.0" encoding="UTF-8"?>, but this
attribute is not required).
Check whether the sc.getRealPath("/XSLT/DirContents.xslt") call really
returns the correct stylesheet (maybe it returns an older version of it
lying around...).
-- Anton Spaans
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top