closing slash in empty element

D

dsmithy

Hi,
Regarding XSLT empty element tags, why does the xsl:stylesheet tag and
the xsl:template tag not have the characteristic self-closing front
slash, while the xsl:eek:utput tag does have the front slash? Is there
something that differentiates these tags that explains the difference
that I'm missing? Is there a general rule that predicts when to
include the ending front-slash and when not to?
Thanks,
Don
 
J

Joe Kesselman

dsmithy said:
Hi,
Regarding XSLT empty element tags, why does the xsl:stylesheet tag and
the xsl:template tag not have the characteristic self-closing front
slash

I think you're confused. Those two are almost never empty.
<xsl:stylesheet> always contains the stylesheet body, and thus ends with
an </xsl:stylesheet> tag at the end of the stylesheet. Similarly, the
body of a template is contained between <xsl:template> and </xsl:template>

If you really wanted one of these to be contentless, you could of course
use the self-closing version. In the case of the stylesheet, that would
be pretty useless. In the case of a template, it might be useful if the
purpose of that template was to discard the matched node without
producing any output in response.


The general rule: In XML, <foo></foo>, with nothing between the
start-element and end-element tags, is semantically identical to <foo/>.


--
Joe Kesselman,
http://www.love-song-productions.com/people/keshlam/index.html

{} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
/\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
 
P

Peter Flynn

dsmithy said:
Hi,
Regarding XSLT empty element tags, why does the xsl:stylesheet tag and
the xsl:template tag not have the characteristic self-closing front
slash,

Because they are not empty elements. They each have an end-tag; at the
end of the stylesheet and the end of the template respectively. Look
closely at an example.
while the xsl:eek:utput tag does have the front slash?

Because it's an empty element.

BTW the word is just "slash", not "front slash". Or perhaps "forward
slash" if you are talking to Windows users who might confuse it with a
backslash.
Is there something that differentiates these tags that explains the
difference that I'm missing?

Yes, see the XML FAQ, question C.12 "Does XML let me make up my own
tags?", the last two paragraphs of the comment at the end by Bob
DuCharme (http://xml.silmaril.ie/authors/makeup/).
Is there a general rule that predicts
when to include the ending front-slash and when not to?

Yes, read the XML Specification, section 3.1 "Start-Tags, End-Tags, and
Empty-Element Tags", subsection "Tags for Empty Elements", production
[44] (http://www.w3.org/TR/2008/REC-xml-20081126/#d0e2480).

When an element is empty, you can use the /> (Null End-Tag) syntax. You
can also use a full end-tag instead, if you wish, so <foo bar="blort"/>
is the same thing as <foo bar="blort"></foo> for all practical purposes.

They are functionally identical, but some users restrict the NET format
to those element types which have been declared EMPTY in the DTD or
Schema (and can thus *never* have any content, by design); and use the
fully-qualified form with end-tag for those element types which *might*
contain subelements or character data (that is, they are allowed to by
the DTD or Schema), but they just don't happen to do so on this
occasion. Largely a distinction without a difference, unless you need
interoperability with SGML.

///Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,005
Messages
2,570,264
Members
46,859
Latest member
HeidiAtkin

Latest Threads

Top