[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: 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

Re:  CSS selectors are syntactic sugar for XPath expressions
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]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.