473,756 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

identically named attributes for one element

Hi everyone,

I was wondering...
Can one element have multiple (identically named) attributes in XML?
e.g. Is the following document valid XML?

<?xml version="1.0" encoding="UTF-8"?>
<root a="1" a="2" a="3"/>

And if it is, how can I create this document with XSLT when this is the input XML?
<?xml version="1.0" encoding="UTF-8"?>
<root>
<a>1</a>
<a>2</a>
<a>3</a>
</root>

It seems that the 'xsl:attribute' element overwrites each attribute (with the same name) that is already present in the result tree element.

Any reactions? Thanks in advance...

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
"Quot capita, tot sententiae" - Terentius , Phormio 454
Jul 20 '05 #1
9 1640


Joris Gillis wrote:

Can one element have multiple (identically named) attributes in XML?
No.
e.g. Is the following document valid XML?

<?xml version="1.0" encoding="UTF-8"?>
<root a="1" a="2" a="3"/>


Validity can only be checked against a DTD or schema thus your question
whether that is "valid" XML should rather be whether the above is
"well-formed" and the answer to that is no, it is not well-formed, see
<http://www.w3.org/TR/2004/REC-xml-20040204/#sec-starttags>
which says:

Well-formedness constraint: Unique Att Spec

An attribute name MUST NOT appear more than once in the same start-tag
or empty-element tag.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
Thanks for your reaction.
Can one element have multiple (identically named) attributes in XML?
No.


So if I say that my XSLT processor (Altova) does not choke on a document with such element and allows me to access all these attributes with '<xsl:apply-templates select="@*"/>', then this means that the software's behaviour is not conform the XML (and XSL) standard?
e.g. Is the following document valid XML?

<?xml version="1.0" encoding="UTF-8"?>
<root a="1" a="2" a="3"/>


Validity can only be checked against a DTD or schema thus your question
whether that is "valid" XML should rather be whether the above is
"well-formed"

Thanks for pointing that out. I keep confusing those terms. The answer to that is no, it is not well-formed, see
<http://www.w3.org/TR/2004/REC-xml-20040204/#sec-starttags>
which says:
Well-formedness constraint: Unique Att Spec

An attribute name MUST NOT appear more than once in the same start-tag
or empty-element tag.


Is there any chance of change regarding this rule in XML? Or is this a fundamental rule that directly reflects the very spirit of XML?
regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
"Quot capita, tot sententiae" - Terentius , Phormio 454
Jul 20 '05 #3
Joris Gillis schrieb:
Thanks for your reaction.
Can one element have multiple (identically named) attributes in XML?

No.


So if I say that my XSLT processor (Altova) does not choke on a document
with such element and allows me to access all these attributes with
'<xsl:apply-templates select="@*"/>', then this means that the
software's behaviour is not conform the XML (and XSL) standard?


Yes, as the XML document itself is not wellformed it should not be
transformed then.
The answer to that is no, it is not well-formed, see
<http://www.w3.org/TR/2004/REC-xml-20040204/#sec-starttags>
which says:
Well-formedness constraint: Unique Att Spec

An attribute name MUST NOT appear more than once in the same start-tag
or empty-element tag.

Is there any chance of change regarding this rule in XML? Or is this a
fundamental rule that directly reflects the very spirit of XML?


The "spirit" is that it is as simple and mighty subset of SGML and not
"we make all your dreams possible"-standard.

What you want is something like:
<ball kind="football" color="black" color="white" color="red"/>
What ever that means it can transformed in some kind of
<ball kind="spirit">
<color>black</color>
<color>white</color>
<color>red</color>
</ball>

An attribute is to describe an element. It just makes no sence to have
several attributes with the same name. As you can not ask the question
"Which color have the (some) ball of kind 'football'?"
Imagine you would answer for the question how old you are:
1st) 20
2nd) 37
3rd) 13

Hope you got the point.

Cheers

Thomas
Jul 20 '05 #4
>> Is there any chance of change regarding this rule in XML? Or is this a
fundamental rule that directly reflects the very spirit of XML?
The "spirit" is that it is as simple and mighty subset of SGML and not
"we make all your dreams possible"-standard.

It rather tends to that type of standard:)

So it's an inherited rule from SGML?
What you want is something like:
<ball kind="football" color="black" color="white" color="red"/>
What ever that means it can transformed in some kind of
<ball kind="spirit">
<color>black</color>
<color>white</color>
<color>red</color>
</ball>

An attribute is to describe an element. It just makes no sence to have
several attributes with the same name. As you can not ask the question
"Which color have the (some) ball of kind 'football'?"
Imagine you would answer for the question how old you are:
1st) 20
2nd) 37
3rd) 13


Yes, off course, it doesn't make sense in these situations, but someone might come op with a real-life use for it.

Quantum mechanincs maybe:
<box>
<cat state="dead" state="alive"/>
</box>
Okay, I'm just kidding:)
P.S. I came up with this thought from an XLST perspective.
(If <xsl:apply-templates select="color"/> works, why not <xsl:apply-templates select="@color"/> ?)
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
"Quot capita, tot sententiae" - Terentius , Phormio 454
Jul 20 '05 #5


Joris Gillis wrote:

Can one element have multiple (identically named) attributes in XML?

No.


So if I say that my XSLT processor (Altova) does not choke on a document
with such element and allows me to access all these attributes with
'<xsl:apply-templates select="@*"/>', then this means that the
software's behaviour is not conform the XML (and XSL) standard?


In my view the XML parser used should raise an error that the parsed
source document is not well-formed when it encounters two attributes
with the same name inside the same tag.
As for XSL or XSLT that standard only speaks of transforming trees, how
the tree is constructed from a source document is not part of the
standard and thus I think it is hard to tell whether an input tree could
be constructed when the source document is not well-formed.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #6
On Wed, 05 Jan 2005 19:31:44 GMT, "Joris Gillis" <ro**@pandora.b e>
wrote:
Is there any chance of change regarding this rule in XML? Or is this a
fundamental rule that directly reflects the very spirit of XML?
The "spirit" is that it is a simple and mighty subset of SGML and not
"we make all your dreams possible"-standard.


It rather tends to that type of standard:)


The "Hype Factor" stuffed into XML already from the start, as given by
several of those media guys who thought they had understood it all as...

"hey, this is cool, I can make up my own tags as I go"

....probably meant a great deal for the impact of XML on the public, as
compared to the level of knowledge and understanding that was spread
earlier for SGML.

But, at least I see from lots of posts here in this NG, today's crowd of
XML'ers are basically struggling with the same type of problems as
SGML'ers used to do back then :-)
So it's an inherited rule from SGML?
You can say that; SGML requires all element attribute names to be unique
as given in an element start tag.

[...]
Quantum mechanics maybe:
<box>
<cat state="dead" state="alive"/>
</box>
Okay, I'm just kidding:)


Yea, I know you are :-)

But seriously, just your markup snip here above happens to point to a
more common misunderstandin g in how to build a markup model that works.

Attributes are not supposed to describe a characteristic part of the
start tag where they happen to live, but instead they are supposed to
describe a characteristic part of the element content that is delimited
by the start and end tag of the element as a whole.

Which means that you can/shall not assign content characteristic
attributes to an "empty" element since such an element does not have any
content in the first place, right?

"cat" in an element start tag must be possible to be recognized as a
noun. Your "cat" markup is treating the element name as if it was an
adjective that needs to be assigned a "value", as in...

<cat breed="Siamese" breed="Burma"/>

....it can just not be made to work in practice :-)

All the best...

--
Rex
Jul 20 '05 #7
> a more common misunderstandin g in how to build a markup model that works.
Attributes are not supposed to describe a characteristic part of the
start tag where they happen to live, but instead they are supposed to
describe a characteristic part of the element content that is delimited
by the start and end tag of the element as a whole.


Really? Then there's something fundamentally wrong with my interpretation of 'markup', if I ever had one... I never had the opportunity to read any book on the subject.
I always assumed that attributes describe a characteristic part of the element (not the element's content).

Thanks for your valuable reaction.

Med bästa hälsningar,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #8
>> So if I say that my XSLT processor (Altova) does not choke on a document
with such element and allows me to access all these attributes with
'<xsl:apply-templates select="@*"/>', then this means that the
software's behaviour is not conform the XML (and XSL) standard?


In my view the XML parser used should raise an error that the parsed
source document is not well-formed when it encounters two attributes
with the same name inside the same tag.
As for XSL or XSLT that standard only speaks of transforming trees, how
the tree is constructed from a source document is not part of the
standard and thus I think it is hard to tell whether an input tree could
be constructed when the source document is not well-formed.

What a remarkable insight you have in these matters... You could be a member of a working group at W3C's (or another consortium)
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #9
On Thu, 06 Jan 2005 18:35:16 GMT, "Joris Gillis" <ro**@pandora.b e>
wrote:

I wrote:
Attributes are not supposed to describe a characteristic part of the
start tag where they happen to live, ... (and I was correct up to about here, and then went on to "flunk" my
words) ... but instead they are supposed to describe a characteristic part
of the element content that is delimited by the start and end tag of
the element as a whole.

[...]
I always assumed that attributes describe a characteristic part of the
element (not the element's content).
Yep, you are correct on that part, sorry for the confusion.

I will refrain from pulling up yet another discussion on where to define
attributes versus elements. The available reading material on that
subject is already as big as it ever needs to be :-)

Still it's my view that markup attributes should be defined sparingly,
many times it is possible to define more simple elements instead, to
achieve the same end result.

Even more to the point, lots of times I keep thinking that empty
elements might be better included in marked up source as processing
instructions.

In your previous example, the "more simple elements" approach would
provide an alternative solution to your initial "problem" for this
thread, e.g.

Instead of,

<cat status="dead" status="alive"/>

why not?

<animal>
<type>cat</type>
<status>dead</status>
<status>alive </status>
<status> ...
</animal>

Given a correct set of semantic definitions and syntax declarations for
the above markup you could be at liberty to include as many different
valid variations of dead, alive and anything in between, as you like.
Med bästa hälsningar,


Jag får önska god fortsättning på det nya året :-)

--
Rex
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
8828
by: Stanimir Stamenkov | last post by:
Using Xerces2 Java I'm trying to validate a CSV data following an XNI example <http://xml.apache.org/xerces2-j/xni-config.html#examples>. The CSV scanner generates XML tree events like: <csv> <row> <col>Andy Clark</col> <col>16 Jan 1973</col> <col>Cincinnati</col>
7
1851
by: Info 3000 | last post by:
Hello, I'm beginner in XML. I have just a little question : I understand that I can write : <Book> <Title> A nice day </Title> <Author> James Nicepen </Author> </Book>
2
6034
by: Mike | last post by:
I´ve got a number of SPAN elements named "mySpan1", "mySpan2", "mySpan3" etc, and want to set their "style.display" to "inline". This works (only needs to work on IE5.5+): for (var x = 1; x < 20; x++) { document.all('mySpan'+x).style.display = "inline"; } But I don´t know how many SPAN elements there are, so I need to set x to a
4
3967
by: Marc Elser | last post by:
Hi Everybody, Can someone please tell me how to access the form name if there's a form field named "name", for example: <form name="myform"> <input type="text" name="name" value="Marc"> <input type="button" onClick="alert(this.form.name);"> </form>
6
3493
by: Developer | last post by:
Hello, I'm experimenting with and XmlTextReader sample, and don't understand how the attributes are being processed. Here's the input: <xsd:element name="AA" type="BB" substitutionGroup="CC"/> The code: while (reader->Read()) {
3
1219
by: Robert Thompson | last post by:
Hello, I'm running into a strange problem involving identically-named variables in multiple projects. I'm using Visual Studio 2005, and have a solution with three projects under it. Two of the three projects have variables with the same name. These variables are both global to their class. The problem is that when variable "foo" in Project 1 is set to "bar," variable foo in Project 2 also immediately takes on value bar. This occurs...
6
1901
by: Jakub.Bednarczuk | last post by:
Hallo everybody I have the problem with getting attributes values and also attributes names. I am reading an xml file with DOM. Lets see an example: file I read <root> <Def></Def> <Elements> <Element att1="1" att2="2" att3="3" //Some attributes are
2
1227
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - My element is named myselect , how do I access it? ----------------------------------------------------------------------- Form controls with any "illegal" characters can be accessed with ` formref.elements"] ` - The bracket characters, amongst others, are illegal in ID attributes and JavaScript identifiers, so you should try to avoid them as browsers...
2
1758
by: Andy Chambers | last post by:
Hi All, Is there a way to define an empty named pattern? Here's the use-case. I'm trying to use relax-ng to specify an extendable schema. Basically, people should be able to tack on whatever they like to a core set of elements/attributes provided their extensions are in a different namespace. It would be nice if I could split it up into
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.