[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]
Re: [xml-dev] CSS selectors are syntactic sugar for XPath expressions
- From: Michael Kay <mike@saxonica.com>
- To: Roger L Costello <costello@mitre.org>
- Date: Mon, 21 Mar 2022 18:01:23 +0000
I don't know CSS well enough to answer your question, but your headline about "syntactic sugar" is way off the mark. The languages have quite different semantics, and overlapping expressive power; the term "syntactic sugar" implies that a trivial conversion is possible from one to the other, and that's certainly not the case.
Michael Kay
Saxonica
> On 21 Mar 2022, at 17:58, Roger L Costello <costello@mitre.org> wrote:
>
> Hi Folks,
>
> Recall that CSS rules consist of two parts: a selector and styling statements. For example, this rule says the content of the <h1> element is to be italicized:
>
> h1 { font-style: italic; }
>
> Multiple elements can be identified in a rule by separating their names with commas, e.g.,
>
> h1, h2, h3 { font-style: italic; }
>
> That is equivalent to these three rules:
>
> h1 { font-style: italic; }
> h2 { font-style: italic; }
> h3 { font-style: italic; }
>
> Both forms say this: Italicize the content of h1 headers; italicize the content of h2 headers; and italicize the content of h3 headers. The styling actions on h1, h2, and h3 are independent of one another.
>
> The CSS selectors are syntactic sugar (convenient shorthand notations) for equivalent XPath expressions. For example:
>
> div //div
> h1 em //h1//em
> .title //*[@class='title']
> #mars //*[@id='mars']
> div#mars //div[@id='mars']
>
> CSS selectors are really nice. They are simple and powerful.
>
> I would like to use the "CSS approach" for a language that I am creating. But there is a problem. Suppose the language that I am creating is to operate on this XML:
>
> <person>
> <name>John Doe</name>
> <telephone>555-123-4567</telephone>
> <latitude>42.366978</latitude>
> <longitude>-71.022362</longitude>
> </person>
>
> The latitude/longitude pair corresponds to the location of Logan airport in Boston. So the XML document shows John Doe at Logan airport. I would like a rule that fuzzes the latitude and longitude elements so that you only know John Doe's location to within a 10 kilometer radius of Boston. One might imagine a rule like this:
>
> latitude, longitude { fuzz_location(...); }
>
> However, the semantics of CSS says that that rule is equivalent to two independent rules:
>
> latitude { fuzz_location(...); }
> longitude { fuzz_location(...); }
>
> That's not what I want. The latitude and longitude values are intertwined; their values must be operated on together, not independently.
>
> I want to avoid using the XPath syntax for selectors, as XPath is too complex for my users.
>
> I want to use the simple CSS syntax, but somehow I need to extend its semantics so that a rule can select a set of elements that are operated on together. Have you done this type of thing -- extended the CSS semantics so that a selected set of elements are operated on together?
>
> /Roger
>
> _______________________________________________________________________
>
> XML-DEV is a publicly archived, unmoderated list hosted by OASIS
> to support XML implementation and development. To minimize
> spam in the archives, you must subscribe before posting.
>
> [Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
> Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
> subscribe: xml-dev-subscribe@lists.xml.org
> List archive: http://lists.xml.org/archives/xml-dev/
> List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
>
[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]