On 7/24/2010 10:45 AM, David Bertoni wrote:
On 7/24/2010 2:44 AM, Richard Webb wrote:
Hi,
I'm trying to execute a stylesheet without an XML source document
using a named template as the entry point of the stylesheet.
I'm trying to work my way through the Xalan-C++ Doxygen API reference
and samples for some examples, so far to no avail.
Can anybody on the list point me in the direction of some sample code
or appropriate API function in the documentation?
When you say "XML source document," I'm going to assume you mean a
source document to transform, not the XML document for the stylesheet.
Given that, you would need at least a trivial source document with a
single element, because the processor needs at least that to operate.
As for starting the execution of the stylesheet from a named template,
there is no facility to do that. The processor needs to perform basic
setup and there's no way to execute that code, then start with a
particular named template.
An easy way to simulate this would be to create a small stylesheet
that imports your stylesheet and have a single template that calls
your named template:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:import href="my-stylesheet.xsl" />
<xsl:template match="/">
<xsl:call-template name="my-template"/>
</xsl:template>
</xsl:stylesheet>
If you need to do this dynamically, you could trivially generate this
stylesheet in memory, then transform from that memory buffer.
I hope that helps.
Dave
Dave is correct, implying something like the following
THE XML DOCUMENT
<dummy_document/>
THE STYLESHEET OR TRANSFORM
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Have one or more of import or include elements, referencing other
stylesheets.
Note that all import elements must precede all include elements -->
<xsl:import href="your-stylesheet-uri"/>
<xsl:output method="..."/>
<xsl:template match="/">
<xsl:call_template name="name_of_imported_template"/>
</xsl:template>
</xsl:stylesheet>
Ref: Your stylesheet that has
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="name_of_imported_template">
<!-- named template content -->
</xsl:template>
</xsl:stylesheet>
=======
At first glance, I was thinking that a <?xml-stylesheet ?>
processing instruction could be used with a #fragment uri
for a stylesheet. But on further analysis, the #fragment
element must be either a stylesheet or transform element
embedded in the referenced XML document. Or the #fragment
referenced element must otherwise have the xsl:version="1.0" attribute
and xmlns:xsl="http://www.w3.org/1999/XSL/Transform" namespace.
========
You might also try this, but it has limitations.
Create an XML document like:
<dummy xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- and the content from your named template here -->
</dummy>
========
I'm unsure of how compatible XALAN is with these fringe uses of the
XSLT-1.0 specification.
XSLT-1.0 requires a document to transform even if the XML document is
an empty element.
- Steve