Transforming numbers to Roman numbers by transforming an XML file via XSLT

隐身守侯 提交于 2019-12-04 16:53:17

Try:

<xsl:template match="calc">
    <xsl:copy>
        <roman>
            <xsl:number value="arab" format="I"/>
        </roman>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>

numbers should be between 1 and 3999.

To validate that the numbers are in the range of 1 to 3999, you could do:

<xsl:template match="calc">
    <xsl:copy>
        <xsl:choose>
            <xsl:when test="1 le number(arab) and number(arab) le 3999">
                <roman>
                    <xsl:number value="arab" format="I"/>
                </roman>
            </xsl:when>
            <xsl:otherwise>
                <xsl:message terminate="no">Please enter a number between 1 and 3999</xsl:message>
            </xsl:otherwise>
        </xsl:choose>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>

Note that Saxon at least supports roman numerals up to 9999: http://xsltransform.net/bEzjRKe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!