closing slash in empty element

Discussion in 'XML' started by dsmithy, Jan 14, 2010.

  1. dsmithy

    dsmithy Guest

    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
     
    dsmithy, Jan 14, 2010
    #1
    1. Advertisements

  2. 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."
     
    Joe Kesselman, Jan 14, 2010
    #2
    1. Advertisements

  3. dsmithy

    Peter Flynn Guest

    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.
    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.
    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/).
    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
     
    Peter Flynn, Jan 17, 2010
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.