[xquery-talk] Roman numeral kata in XQuery

Matthias Brantner matthias.brantner at 28msec.com
Mon May 16 10:37:08 PDT 2011


some XQuery processors (e.g. Zorba) already implement the latest working draft of
XQuery 3.0 (see http://www.w3.org/TR/xquery-30/). This provides two interesting
features related to your example.

1. A switch expression (http://www.w3.org/TR/xquery-30/#id-switch)
  switch ($input)                                                                                                     
    case "I" return 1                                                                                                 
    case "V" return 5                                                                                                 
    case "X" return 10                                                                                                
    case "L" return 50                                                                                                
    case "C" return 100                                                                                               
    case "D" return 500                                                                                               
    case "M" return 1000                                                                                              
    default return 0

2. The XQuery 3.0 function library (see http://www.w3.org/TR/xpath-functions-30/#func-format-integer)
provides a function for the reverse conversion (i.e. integer to roman numeral). For example, 
format-integer(55, 'I').

Best regards


On May 11, 2011, at 5:51 PM, Mattio Valentino wrote:

> Hello,
> I hope this isn't too odd of a request.
> I wanted a little XQuery practice so I decided to try to port some
> code katas. I did the Roman numeral one first.
> Would anyone mind reviewing the solution I have here?
> http://bitbucket.org/mattio/xquery-katas/src/5ffd02da6f83/src/roman-numerals.xq
> There's no point practicing if I'm just going to reinforce bad habits! ;-)
> Thanks,
> Mattio
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk

More information about the talk mailing list