Re: [xsl] Finding an element without a particular attribute?

Subject: Re: [xsl] Finding an element without a particular attribute?
From: "Michael Kay michaelkay90@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 28 Mar 2025 17:51:54 -0000
>I turn the value of the @key attribute into the element's name (supposing it
is a NCName) and add a type attribute to reflect that it was an array, a map,
a string, etc..

We often have a choice here: use an element name to say what kind of thing
you've got, and an attribute to say what role it plays relative to its parent
element; or do it the other way around, with an element name to indicate the
role, and an attribute to indicate the type.

For example you can do

<movie>
   <person role="director">....</person>
   <person role="female-lead">.... </person>
   <company role="sponsor">...
</movie>

or you can do

<movie>
   <director entity="person">...</director>
   <female-lead entity="person">...</female-lead>
   <sponsor entity="company">...</sponsor>
</movie>

There are pros and cons for both, and in a sense they are obviously
equivalent. But the biggest argument for doing it the first way is that schema
and DTD validation is all based on element names, not on attribute values.

In JSON you're pretty much forced into using role-names as keys, for
uniqueness, so it becomes

{
   "director": { .... }
   "female-lead": { ....}
   "sponsor": { ....}
}

This is one of the reasons conversion between XML and JSON is often tricky.

Michael Kay
Saxonica

Current Thread