[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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


Subject: Re: [xsl] Translating roman numerals into integers with XSLT 2.0
From: António Mota <xptm@xxxxxxx>
Date: Tue, 21 Dec 2004 16:05:14 +0000

Just jumped in on this thread, it seems interesting altought i won't use for
now, but:

1) It works only with XSLT 2.0 as the Subject sugests or with 1.0 too?

2) Is it well tested?

3) If 2==true, it'll go to the List FAQ?

Cheers.

Quoting Mukul Gandhi <mukul_gandhi@xxxxxxxxx>:

> Following is an improved algorithm.. It will work for
> any large number..
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:num="http://whatever" version="2.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:choose>
>     <xsl:when test="num:toRoman($index) =
> $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:function name="num:toRoman" as="xs:string">
>   <xsl:param name="value" as="xs:integer"/>
>   <xsl:number value="$value" format="I"/>
> </xsl:function>
>
> </xsl:stylesheet>
>
> Regards,
> Mukul
>
> --- Mukul Gandhi <mukul_gandhi@xxxxxxxxx> wrote:
>
> > You could try something like this -
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xsl:stylesheet
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >
> >
> > xmlns:xs="http://www.w3.org/2001/XMLSchema"
> >
> > xmlns:num="http://whatever" version="2.0" >
> >
> > <xsl:output method="text"/>
> >
> > <xsl:variable name="max" select="10000" />
> >
> > <xsl:template match="/">
> >   <xsl:call-template name="RomanToInteger">
> >     <xsl:with-param name="roman_number"
> > select="'XXI'"
> > />
> >   </xsl:call-template>
> > </xsl:template>
> >
> > <xsl:template name="RomanToInteger">
> >   <xsl:param name="roman_number" />
> >   <xsl:for-each select="1 to $max">
> >     <xsl:if test="num:toRoman(.) = $roman_number">
> >       <xsl:value-of select="." />
> >     </xsl:if>
> >   </xsl:for-each>
> > </xsl:template>
> >
> > <xsl:function name="num:toRoman" as="xs:string">
> >   <xsl:param name="value" as="xs:integer"/>
> >   <xsl:number value="$value" format="I"/>
> > </xsl:function>
> >
> > </xsl:stylesheet>
> >
> > The above XSL assumes, that there is some maximum
> > value of the number(in this example 10000).
> >
> > I see this as an area of improvement..
> >
> > Is there a way to break from xsl:for-each loop when
> > some condition is met?
> > here , xsl:if test="num:toRoman(.) = $roman_number"
> >
> > Regards,
> > Mukul
> >
> > --- Huditsch Roman <Roman.Huditsch@xxxxxxxxxxxxx>
> > wrote:
> >
> > > Hi again,
> > >
> > > Sorry, for bothering you a second time today,
> > > but I was wondering if there is a more or less
> > > simple way
> > > of translating roman numerals into intergers with
> > > XSLT 2.0.
> > >
> > > Or do I have to use the standard method for doing
> > > this
> > > describes in the "XSLT Cookbook" by Sal Mangano?
> > >
> > > Would be nice if format-number() or anything
> > similar
> > > would allow
> > > me to o this...
> > >
> > > Thank you very much for your patience.
> > >
> > > wbr,
> > > Roman
> > >
> > > _______________________________________
> > >
> > > Roman Huditsch
> > > IT and Electronic Publishing
> > > LexisNexis ARD Orac
> > > Marxergasse 25
> > > 1030 Vienna
> > > Austria
> > > ph: +43-1-534 52-1514
> > > f: +43-1-534 52-140
> > > e-mail roman.huditsch@xxxxxxxxxxxxx
> > > www.lexisnexis.at
> > >
> > >
> > > > -----Urspr|ngliche Nachricht-----
> > > > Von: Michael Kay [mailto:mike@xxxxxxxxxxxx]
> > > > Gesendet: Montag, 20. Dezember 2004 15:20
> > > > An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > > Betreff: RE: [xsl] Omitting default namespace in
> > > the output - XSLT 2.0
> > > >
> > > > If you copy elements using xsl:copy-of, the
> > output
> > > elements
> > > > will have the same names as the input elements,
> > > and the
> > > > system will automatically add declarations of
> > the
> > > namespaces
> > > > used in these names. You want your output
> > elements
> > > to have a
> > > > different name from the input elements (same
> > local
> > > name,
> > > > different URI). So you can't use copy-of.
> > > >
> > > > To copy a tree while renaming elements, use a
> > > modified form
> > > > of the identity template rule:
> > > >
> > > > <xsl:template match="*">
> > > > <xsl:element name="{local-name()}">
> > > >   <xsl:copy-of select="@*"/>
> > > >   <xsl:apply-templates/>
> > > > </xsl:element>
> > > > </xsl:template>
> > > >
> > > > Michael Kay
> > > > http://www.saxonica.com/
> > > >
> > > >
> > > > > -----Original Message-----
> > > > > From: Huditsch Roman
> > > [mailto:Roman.Huditsch@xxxxxxxxxxxxx]
> > > > > Sent: 20 December 2004 13:52
> > > > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > > > Subject: [xsl] Omitting default namespace in
> > the
> > > output - XSLT 2.0
> > > > >
> > > > > Hi,
> > > > >
> > > > > Given an example input like:
> > > > >
> > > > > <?xml version="1.0" encoding="UTF-8"?> <norm
> > > > > xmlns="myDefaultNamespace">
> > > > > 	<table>
> > > > > 		<row>
> > > > > 			<cell>My Table</cell>
> > > > > 		</row>
> > > > > 	</table>
> > > > > </norm>
> > > > >
> > > > > I searched for an easy way to get output data,
> > > which is not
> > > > associated
> > > > > to my default namespace any more, with the
> > help
> > > of <xsl:copy-of> in
> > > > > XSLT 2.0 I hoped that the attribute
> > > "copy-namespaces" set to "no"
> > > > > would help me here, but unfortunately I had no
> > > luck with Saxon 8.1.1
> > > > >
> > > > > My output still looks like
> > > > >
> > > > > <table>
> > > > > 	<row xmlns="myDefaultNamespace">
> > > > > 		<cell>My Table</cell>
> > > > > 	</row>
> > > > > </table>
> > > > >
> > > > >
> > > > > XSLT:
> > > > > =====
> > > > >
> > > > > 	<xsl:template match="ln:table">
> > > > > 		<table>
> > > > > 			<xsl:copy-of select="node() | @*"
> > > > > copy-namespaces="no"/>
> > > > > 		</table>
> > > > > 	</xsl:template>
> > > > >
> > > > >
> > > > > Thanks in advance for your input!
> > > > >
> > > > > wbr,
> > > > > Roman
> > > > > _______________________________________
> > > > >
> > > > > Roman Huditsch
> > > > > IT and Electronic Publishing
> > > > > LexisNexis ARD Orac
> > > > > Marxergasse 25
> > > > > 1030 Vienna
> > > > > Austria
> > > > > ph: +43-1-534 52-1514
> > > > > f: +43-1-534 52-140
> > > > > e-mail roman.huditsch@xxxxxxxxxxxxx
> > > > > www.lexisnexis.at
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - Helps protect you from nasty viruses.
> http://promotions.yahoo.com/new_mail
>
>





O SAPO ja esta livre de vmrus com a Panda Software, fique vocj tambim!
Clique em: http://antivirus.sapo.pt


Current Thread
Keywords