Re: Need to output an opening or closing tag by itself
<xsl:template match="e"> <xsl:choose> <xsl:when test="@t ='a'"> <e> </xsl:when> <xsl:when test="@t ='b'"> </e> </xsl:when> <xsl:otherwise> <xsl:message terminate="yes"> Unexpected data in attribute t. </xsl:message> </xsl:otherwise> </xsl:choose> </xsl:template>
Even if it worked (the code is syntactically broken), this approach constitutes "tag-writing", and won't work in XSLT for reasons others will explain (or have done so). XSLT doesn't work with tags; it works on a tree of nodes derived from the tagging of the input: elements, attributes and text arranged in a hierarchy, and it builds the same kind of tree.
Your problem is properly approached, in XSLT, as a grouping problem. The nodes between the 'e' elements must be grouped together.
As such, it infers a structure that is only implicit in the original data, and thus qualifies as an "upconversion" (a transformation that adds information). Accordingly, it isn't going to be easy without using features designed for this purpose. Most of these make an appearance only in XSLT 2.0, although techniques have been devised in XSLT 1.0 to accomplish it (such as sibling recursion or structural induction using keys to associate the groups).
If you really want to use a tag-writing approach to transformation, even in XSLT, that can be done, but (a) experience has shown that past trivial cases it's generally much more work than the orthodox method (indeed, much of this experience was won in the 1990s and earlier, before XSLT even existed), and (b) it introduces an architectural dependency. Specifically, the output must be written as a file, something that is not necessary in many XML processing architectures for which XSLT is well suited.
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
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