[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]
Re: [xml-dev] Why is an attribute used to name/identify a chunk of markup?
- From: "G. Ken Holman" <gkholman@CraneSoftwrights.com>
- To: Roger L Costello <costello@mitre.org>,"xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
- Date: Sun, 27 Feb 2022 11:22:24 -0500
Attribute vs. element has been long debated since SGML days. I think
someone may have picked up the movie rights.
Early opinions (including mine) are found at:
http://xml.coverpages.org/elementsAndAttrs.html
I hope this helps.
. . . . . Ken
At 2022-02-26 20:20 +0000, Roger L Costello wrote:
Hi Folks,
An XSLT function is XML. XSLT functions are expressed this way:
<xsl:function name="f:my-function">
<!-- do something -->
</xsl:function>
It has an element, function, which is bound to the XSLT namespace.
It has an attribute, name. The purpose of the name attribute is to
name the function (i.e., name a chunk of markup).
Why did they (the XSLT working group) design the XML that way?
Specifically, why did they use an attribute for providing the name
of the function? Why didn't they use an element:
<xsl:function>
<name>f:my-function</name>
<!-- do something -->
</xsl:function>
An XML Schema element declaration is XML. Element declarations are
expressed this way:
<xs:element name="Book">
<!-- declare it -->
</xs:element>
Why did they (the XML Schema working group) design the XML that way?
Specifically, why did they use an attribute for providing the name
of the element? Why didn't they use an element:
<xs:element>
<name>Book</name>
<!-- declare it -->
</xs:element>
An XML RDF document is XML. RDF items are expressed this way:
<River rdf:ID="Yangtze">
<!-- describe something -->
</River>
Why did they (the RDF working group) design the XML that way?
Specifically, why did they use an attribute for providing the
identity of the item? Why didn't they use an element:
<River>
<rdf:ID>Yangtze</rdf:ID>
<!-- describe something -->
</River>
In each case the XML was designed using an attribute rather than an
element. Why? Which of these is the reason:
* The choice of using an attribute rather than element was
completely arbitrary.
* They wanted to save a few bytes, so they used an attribute
rather than an element.
* Attributes have scope. The scope is from the start tag to the
matching end tag. So in <xsl:function name="f:my-function"> the
name applies from <xsl:function> to </xsl:function>. That is, the
name applies over the whole function. That's exactly what we want,
for the name to apply over the whole chunk of markup. Conversely,
if an element had been used, <name>f:my-function</name>, it does
not have scope over the entire function. Ditto for the XML Schema
example and the RDF example.
* [Before you tell me: "The XML specification says nothing about
attributes having scope." I know. However, there is strong
empirical evidence that XML developers and users *do* treat
attributes as having an implied scope.]
* It is a convention among XML developers and users to use an
attribute to name/identify a chunk of markup.
* Other (what?)
/Roger
--
Contact info, blog, articles, etc. http://www.CraneSoftwrights.com/x/ |
Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
Streaming hands-on XSLT/XPath 2 training class @US$125 (5 hours free) |
Essays (UBL, XML, etc.) http://www.linkedin.com/today/author/gkholman |
[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]