RE: [xsl] How to output open/close tags independently?

Subject: RE: [xsl] How to output open/close tags independently?
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Thu, 26 Dec 2002 10:18:22 -0500
[Edward L. Knoll]
> 
> I am creating a XSL stylesheet which effectively copies an 
> input XML stream to the output and introduces a level of XML 
> elements for a
> selected set of elements.   The problem I have run into is that there
> does seem to be way to output the open tag of an element 
> separately from the closing tag.  I've come up with something 
> which works using <xsl:text> to output the open and close 
> tags; in short, I have to hide the fact I'm outputting 
> elements.  I am generating well-formed XML, however, I can't 
> seem to come up with a method which allows the elements to be 
> recognized as such while keeping the XSL well-formed.
> 

This kind of question seems to be coming up more and more frequently.
There are two things to say, both of which are covered in the various
FAQs -

1) This seems to be a grouping problem - search for "grouping" in the
archives and FAQs.

2) DO NOT try to emit start tags (or end tags) independently.  There is
almost never a need to do so, and it is VERY unlikely that your problem
is one of the exceptions.  Exceptions almost always require outputting
non-well-formed non-xml for some good reason. 

You think that you need to output start tags separately because you do
not yet fully understand the nature of the transformation you want to
accomplish - at least not in xslt terms.  In xslt terms, you want to
select certain sets of nodes and then to build complete elements with
them.  The output comes AFTER the processor has build a tree of result
nodes.  

XSLT is by definition well-formed xml, so you cannot write an unbalanced
set of tags and have the stylesheet make it through the parser.  Since
it builds a tree, which is also by definition well-formed, you should
work with the processor to build the **tree** that you want.  You should
not try to bypass that by creating text nodes in the result tree that
**look** like markup (for various good reason that appear in the FAQs).

If you will explain your problem clearly and concisely, you will get
plenty of help from the list.

Also look for my post on 10-23-2002 with the subject "RE: [xsl] Newbie,
question about looping" for more on this subject.

Cheers,

Tom P

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread