OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] An approach to describing the relationships between units-

[ Lists Home | Date Index | Thread Index ]

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/





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS