Re: AW: [xsl] Translating roman numerals into integers with XSLT 2.0

Subject: Re: AW: [xsl] Translating roman numerals into integers with XSLT 2.0
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Tue, 21 Dec 2004 09:06:59 -0800 (PST)
Of course, the XSLT 2.0 stylesheet will not work with
1.0 processor.

We need to write a different stylesheet for XSLT 1.0
processors. The only change will be, that we need to
write a named template instead of a xsl:function .. I
am presenting below a XSLT 1.0 solution also..

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
    
<xsl:output method="text"/>
    
<xsl:template match="/">
  <xsl:call-template name="RomanToInteger">
    <xsl:with-param name="roman_number" select="'XXI'"
/> 
    <xsl:with-param name="index" select="1" /> 
  </xsl:call-template>        
</xsl:template>
    
<xsl:template name="RomanToInteger">
  <xsl:param name="roman_number" />
  <xsl:param name="index" />
  <xsl:variable name="temp">
    <xsl:call-template name="toRoman">
      <xsl:with-param name="value" select="$index" /> 
       
    </xsl:call-template>        
  </xsl:variable>
  <xsl:choose>    
    <xsl:when test="$temp = $roman_number">
      <xsl:value-of select="$index" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:call-template name="RomanToInteger">
        <xsl:with-param name="roman_number"
select="$roman_number" /> 
        <xsl:with-param name="index" select="$index +
1" /> 
      </xsl:call-template>
    </xsl:otherwise>
  </xsl:choose>  
</xsl:template>
    
<xsl:template name="toRoman">
  <xsl:param name="value"/>
  <xsl:number value="$value" format="I"/>
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

> > Von: Antsnio Mota [mailto:xptm@xxxxxxx] 
> > Gesendet: Dienstag, 21. Dezember 2004 17:05
> > An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Betreff: Re: [xsl] Translating roman numerals into
> integers 
> > with XSLT 2.0
> > 
> > 1) It works only with XSLT 2.0 as the Subject
> sugests or with 1.0 too?
> > 




		
__________________________________ 
Do you Yahoo!? 
Jazz up your holiday email with celebrity designs. Learn more. 
http://celebrity.mail.yahoo.com

Current Thread