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

Re: An approach to describing the relationships between units-


describing your relationships
Hi Dare,

> I wouldn't mind being able to create extension types and extension
> functions in XSLT that could manipulate units of measure as
> intrinsic types the same way strings, booleans and numbers are
> supported (plus dates if you use EXSLT).

Right. That was the kind of thing that the proof-of-concept
implementation from http://www.jenitennison.com/datatypes/ was
supposed to emulate. Obviously it can't hook into the comparison
operators in XPath, but it defines the functions you need.

So you'd define your measurements with:

<datatypes xmlns="http://www.jenitennison.com/datatypes"
           ns="http://www.example.com/datatypes/measurements">

<datatype name="kilometre">
  <parse><ref name="number" /></parse>
</datatype>

<datatype name="mile">
  <parse><ref name="number" /></parse>
</datatype>

<cast from="kilometre" to="mile">
  <value-of select=". div 1.62" />
</cast>

<cast from="mile" to="kilometre">
  <value-of select=". * 1.62" />
</cast>

<define name="number">
  <ref name="digits" />
  <optional><string>.</string><ref name="digits" /></optional>
</define>

<define name="digits">
  <oneOrMore>
    <charGroup><range from="0" to="9" /></charGroup>
  </oneOrMore>
</define>

</datatypes>

Run it through the datatypes.xsl stylesheet and you'd get an XSLT 2.0
stylesheet that defines a bunch of functions for these datatypes.
Import that into your stylesheet, and you can do things like:

  m:compare-miles(m:mile('2000'),
                  m:mile(m:kilometre(River/@length)))

and you'd get -1 if the River is less than 2000 miles long, 1 if the
River is more than 2000 miles long, and 0 if it was exactly 2000 miles
long.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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.