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. Advertising

  2. dsmithy wrote:
    > 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."
     
    Joe Kesselman, Jan 14, 2010
    #2
    1. Advertising

  3. dsmithy

    Peter Flynn Guest

    dsmithy wrote:
    > 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
    --
    XML FAQ: http://xml.silmaril.ie/
     
    Peter Flynn, Jan 17, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John

    empty/non-empty element

    John, Jul 15, 2003, in forum: XML
    Replies:
    1
    Views:
    1,051
    Klaus Johannes Rusch
    Jul 16, 2003
  2. Lukas
    Replies:
    3
    Views:
    847
    spiff
    Nov 10, 2005
  3. =?Utf-8?B?Vk1J?=

    Closing popup window when closing parent window?

    =?Utf-8?B?Vk1J?=, Feb 14, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    666
    Thomas Hansen
    Feb 15, 2007
  4. Aniais
    Replies:
    5
    Views:
    611
    Joe (GKF)
    Dec 17, 2006
  5. Jaap
    Replies:
    0
    Views:
    536
Loading...

Share This Page