bartneck / swiML

A project to formalise swimming programs using XML
MIT License
2 stars 2 forks source link

create roman numeral #64

Open bartneck opened 6 months ago

bartneck commented 6 months ago

find a way to express any numbers as roman numeral

bartneck commented 6 months ago

This is as simple as writing

bartneck commented 6 months ago

Or like this: produces the text MCMLXV.

bartneck commented 6 months ago

It is also possible to use string format-number(number,format,[decimalformat])

bartneck commented 6 months ago

It would be useful to have a global parameter so that we do not have to duplicate the whole XSLT file for roman numerals.

bartneck commented 3 months ago

The format="I" only works for xsl:numbers. The format-number() function does not include the option for "I". It is possible to create a new function (below). Would this interfere with the layout calculations? The number 10 would no longer have two digits, but just on: X.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:num="http://example.com/num"
    exclude-result-prefixes="num"
    version="3.0">

  <xsl:function name="num:roman" as="xs:string">
    <xsl:param name="value" as="xs:integer"/>
    <xsl:number value="$value" format="i"/>
  </xsl:function>

  <!-- Example usage -->
  <xsl:template match="/">
    <output>
      <xsl:value-of select="num:roman(100)"/>
    </output>
  </xsl:template>

</xsl:stylesheet>
bartneck commented 3 months ago

Using this function on pool length produces the right results, but when trying it for the lengthAsDistance we get an error message:

<xsl:value-of select="../ancestor-or-self::*[sw:lengthAsDistance]"/>

or

<xsl:value-of select="sw:numroman(sw:lengthAsDistance)"/>

Gives this error message:

An empty sequence is not allowed as the first argument of sw:numroman()