Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Help deciphering use of square brackets within translate function

From: johkar <nosendjunk@---.--->
To: NULL
Date: 7/9/2009 12:08:00 PM
On Jul 9, 2:03=A0pm, johkar <nosendj...@msn.com> wrote:
> On Jul 3, 11:27=A0am, cms...@acm.org (C. M. Sperberg-McQueen) wrote:
>
>
>
>
>
> >johkar<nosendj...@msn.com> writes:
> > > To me, the inner translate function below would find any instance of
> > > square brackets with a single space separating them and replace it
> > > with a single underscore but that doesn't seem to be what is
> > > happening. =A0Do the square brackets have some sort of
> > > significance...like a regular expression? =A0I didn't think so since
> > > they were quoted. =A0I think the original developer's intent was to
> > > replace spaces with underscores so that the element name syntax would
> > > be valid XML.
>
> > The second argument to translate() is interpreted as a set of
> > characters, not as an expression. =A0The first argument is scanned
> > character by character, and each character is tested to see if it
> > appears anywhere in the second argument. =A0If it does not appear in th=
e
> > second argument, it's copied to the output string without change. =A0If
> > it does appear in the second argument at position N, then it's
> > replaced in the output by the character at position N of the third
> > argument. =A0If the third argument is less than N characters long,
> > the character is omitted from the output.
>
> > This behavior will be familiar to some people from analogous
> > functions and operations in Snobol, Spitbol, Rexx, and
> > IBM 360 assembler, as well as (I think) some other languages.
>
> > > However if the XML contains:
>
> > > <rate>FCTR[ =A0 ]2</rate> =A0 it transforms into =A0<FCTR2>0.04200</F=
CTR2>
> > > without any underscore at all.
>
> > > <xsl:variable name=3D"tag" select=3D"translate(translate(rateCode/tex=
t
> > > (),'[ ]','_'),'.','__')"/>
> > > <xsl:element name=3D"{$tag}">
> > > =A0 =A0<xsl:value-of select=3D"rateTag/text()"/>
> > > </xsl:element>
>
> > > Any insight into this would be appreciated.
>
> > The inner call, to
>
> > =A0 =A0 translate(rateCode/text(),'[ ]','_')
>
> > should translate left square bracket to underscore and omit any
> > blanks or right square brackets. =A0In your example, the element is
> > named rate, not rateCode, which means we cannot tell what the
> > first argument of the inner call to translate() is. =A0If the
> > XML actually contains <rateCode>FCTR[ =A0 ]2</rateCode>, then I
> > would expect the call to produce "FCTR_2". =A0The outer call is then
>
> > =A0 =A0 translate("FCTR_2",'.','__')
>
> > and since no full stops appear in the first argument, the result
> > would be FCTR_2. =A0This is what you say you expected, but the
> > reasoning is rather different.
>
> > If there is a rateCode element in the vicinity, then the result
> > will depend on its content.
>
> > Are you sure you transcribed both the input and the XSLT
> > correctly here?
>
> > hth
>
> > --
> > ****************************************************************
> > * C. M. Sperberg-McQueen, Black Mesa Technologies LLC
> > *http://www.blackmesatech.com
> > *http://cmsmcq.com/mib
> > *http://balisage.net
> > ****************************************************************
>
> Thanks for the reply, I am still not quite getting why the rateCode is
> getting transformed into FCTR2 without the underscore. =A0You stated
> that rateCode "should translate left square bracket to underscore and
> omit any blanks or right square brackets"...why would you expect
> that...just trying to understand.
>
> <rateCode>FCTR[ =A0 ]2</rateCode>
> <rateTag>0.04200</rateTag>
>
> transforms into
>
> <FCTR2>0.04200</FCTR2> without any underscore at all.
>
> <xsl:variable name=3D"tag" select=3D"translate(translate(rateCode/text
> (),'[ ]','_'),'.','__')"/>
> <xsl:element name=3D"{$tag}">
> =A0 =A0<xsl:value-of select=3D"rateTag/text()"/>
> </xsl:element>- Hide quoted text -
>
> - Show quoted text -

Also, if rateCode has spaces in it, it is converted to:

<FCTR2>0.04200</FCTR2>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent