[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-
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! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|