|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Generating embedded XSL stylesheet using XSLT
Hi from a newbie --
I'm trying to create an XSL stylesheet which generates an XML document with an embedded XSL stylesheet. I'm using Cocoon. The problem is that I can't seem to be able to declare the xmlns:xsl namespace _in the generated xsl:stylesheet element_. I'm using xsl:namespace-alias. My generated XML document has the xmlns:xsl declaration at the root element instead. Cocoon won't process the embedded stylesheet. If I manually move the namespace declaration in the generated document to the xsl:stylesheet element and process it, it works. I've been able to get around this by constructing the stylesheet with xsl:element (as described in the FAQ), but this generates a weird prefix n0 for it and its children, _and_ I have to construct all of the children with similar xsl:element commands, which is _very_ cumbersome. (These working but very inelegant examples not included.) My examples: <?xml version="1.0"?> <sf:stylesheet version="1.0" xmlns:sf="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="this_space_intentionally_left_blank"> <sf:namespace-alias stylesheet-prefix="xsl" result-prefix="sf"/> <sf:template match="/form"> <sf:processing-instruction name="cocoon- format">type="text/xml"</sf:processing-instruction> <sf:processing-instruction name="cocoon- process">type="xslt"</sf:processing-instruction> <sf:processing-instruction name="xml- stylesheet">href="#ibnsina" type="text/xsl"</sf:processing-instruction> <document> <formdata> <sf:copy-of select="document('srctest2.xml')"/> </formdata> <dummy/> <xsl:stylesheet id="ibnsina"> <xsl:template match="formdata"/> <xsl:template match="xsl:stylesheet"/> <xsl:template match="dummy"> <html> <head> <title>Test succeeded!</title> </head> <body> <p><xsl:value-of select="/document/formdata/form/someOtherNode"/></p> </body> </html> </xsl:template> </xsl:stylesheet> </document> </sf:template> </sf:stylesheet> Given a very simple root tree and a similarly simple srctest2.xml file, this generates: [formatted for visual reasons purely] <?xml version="1.0" encoding="UTF-8"?> <?cocoon-process type="xslt"?> <?xml-stylesheet href="#ibnsina" type="text/xsl"?> <document xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <formdata> <form> <someOtherNode>Some other data</someOtherNode> </form> </formdata> <dummy/> <xsl:stylesheet id="ibnsina"> <xsl:template match="formdata"/> <xsl:template match="xsl:stylesheet"/> <xsl:template match="dummy"> <html> <head> <title>Test succeeded!</title> </head> <body> <p><xsl:value-of select="/document/formdata/form/someOtherNode"/></p> </body> </html> </xsl:template> </xsl:stylesheet> </document> <!-- This page was served in 199 milliseconds by Cocoon 1.8.2 --> If I move the xmlns:xsl declaration from the document element to the xsl:stylesheet element, the styelsheet works. Otherwise, it doesn't. Is there a way for me to force Cocoon to include the declaration in the xsl:stylesheet element? I've tried for three days now, and am getting a bit desperate. Sorry if this has been asked before; I couldn't find it in the FAQ nor by browsing the mailing list archives for the past three months. Other approaches are also appreciated, of course. Thanks in advance, Petteri Sulonen XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








