Re: How to select a document element from the input xm
I'm afraid you may have confused your friendly instructors by referring to a "document element". Reading your post, I infer what you mean by this is the DOCTYPE declaration, i.e. that thing at the top of your input file looking like
<!DOCTYPE element SYSTEM "http://delete.dtd">
... but this isn't an element at all, much less the "document element" which is something else entirely (it's the element at the top level of your document, the one that contains everything else, that is whose end tag appears at the end of the document).
Jumping ahead -- as you've found, you can control what your processor writes as a DOCTYPE declaration in xsl:output -- but only up to a point. What you *can't* do (as you found) is parameterize this control or make it dynamic in any way, by (for example) wrapping it in an xsl:choose. This is because it is not really an XSLT instruction, but only a literal value the processor hands to the serializer to use when it writes the output file.
More control over this will be possible in XSLT 2.0, but in the meantime the way people handle this is by using stylesheets to write stylesheets. The first stylesheet writes a stylesheet, which is then executed in a subsequent pass. This is what the posts responding so far have been getting at: since you can't control this string directly, you do it indirectly by creating the entire stylesheet dynamically (!).
But I think this is overkill for you. Rather, I think you'll do better to handle your conditional logic outside the stylesheet altogether. Have three stylesheets:
templates.xsl contains all your templates.
deletedoc.xsl contains (only) the following:
<xsl:include href="templates.xsl"/> <xsl:output method="xml" doctype-system="http://delete.dtd"/>
and updatedoc.xsl contains the same, only invoking update.dtd.
Then you need only to implement logic in the calling environment to call deletedoc.xsl for "delete" documents, and update.xsl for "update" documents, and you're there. (How you do this will depend, of course.)
This is the XSL-orthodox way to do it: XSLT is designed on the assumption that the host system knows how to delegate each type of document to its own proper stylesheet(s), and doesn't mandate (or include) any way to manage that delegation itself. But by using xsl:include, you manage to share templates (and maintenance) between what are formally two different stylesheets. (You could also use xsl:import.)
If this isn't sufficient, please say why and we'll try to clear it up further.
At 03:10 PM 7/12/2004, you wrote:
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