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/10/2009 10:52:00 AM
On Jul 9, 6:57=A0pm, cms...@acm.org (C. M. Sperberg-McQueen) wrote:
> johkar<nosendj...@msn.com> writes:
> > 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.
>
> As I wrote in my previous note,
>
> =A0 =A0 The first argument is scanned character by character, and each
> =A0 =A0 character is tested to see if it appears anywhere in the second
> =A0 =A0 argument. =A0If it does not appear in the second argument, it's
> =A0 =A0 copied to the output string without change. =A0If it does appear =
in
> =A0 =A0 the second argument at position N, then it's replaced in the
> =A0 =A0 output by the character at position N of the third argument. =A0I=
f
> =A0 =A0 the third argument is less than N characters long, the character
> =A0 =A0 is omitted from the output.
>
> That was my attempt to explain why I would expect that. =A0If it
> didn't help, let me try again.
>
> The inner call to translate() has three arguments:
>
> =A0 (1) the string "FCTR[ =A0 ]2"
> =A0 (2) the string "[ ]"
> =A0 (3) the string "_"
>
> The function constructs an output string by walking through the input
> string character by character and possibly adding something to the
> output string.
>
> Character 1: =A0"F".
>
> =A0 Look for an "F" in argument 2. =A0Find none.
> =A0 Place "F" in the output string, which is now "F".
>
> Character 2: =A0"C".
>
> =A0 Look for a "C" in argument 2. =A0Find none.
> =A0 Place "C" in the output string, which is now "FC".
>
> Character 3: =A0"T".
>
> =A0 Look for a "T" in argument 2. =A0Find none.
> =A0 Place "T" in the output string, which is now "FCT".
>
> Character 4: =A0"R".
>
> =A0 Look for an "R" in argument 2. =A0Find none.
> =A0 Place "R" in the output string, which is now "FCTR".
>
> Character 5: =A0"[".
>
> =A0 Look for an occurrence of "[" in argument 2. =A0Find one
> =A0 at position 1. =A0Look up the character in position 1
> =A0 of argument 3; find "_". =A0Add that character ("_")
> =A0 to the output string, which is now "FCTR_".
>
> Character 6: =A0" ".
>
> =A0 Look for an occurrence of " " in argument 2. =A0Find one
> =A0 at position 2. =A0Look up the character in position 2
> =A0 of argument 3; discover that there isn't one (argument
> =A0 3 is one character long). =A0So add nothing to the
> =A0 output string; it remains "FCTR_".
>
> Character 7: =A0" ".
>
> =A0 Look for an occurrence of " " in argument 2. =A0Find one
> =A0 at position 2. =A0Look up the character in position 2
> =A0 of argument 3; discover that there isn't one (argument
> =A0 3 is one character long). =A0So add nothing to the
> =A0 output string; it remains "FCTR_".
>
> Character 8: =A0" ".
>
> =A0 Look for an occurrence of " " in argument 2. =A0Find one
> =A0 at position 2. =A0Look up the character in position 2
> =A0 of argument 3; discover that there isn't one (argument
> =A0 3 is one character long). =A0So add nothing to the
> =A0 output string; it remains "FCTR_".
>
> Character 9: =A0"]".
>
> =A0 Look for an occurrence of "]" in argument 2. =A0Find one
> =A0 at position 3. =A0Look up the character in position 3
> =A0 of argument 3; discover that there isn't one (argument
> =A0 3 is one character long). =A0So add nothing to the
> =A0 output string; it remains "FCTR_".
>
> Character 10: =A0"2".
>
> =A0 Look for an occurrence of "2" in argument 2. =A0Find none.
> =A0 So add "2" to the output string, which is now "FCTR_2".
>
> End of argument 1: return the output string, now "FCTR_2".
>
> The details for characters 5 through 9 should make clear that what
> translate() may be expected to do with second and third arguments of
> "[ ]" and "_" is to replace "[" with "_" and delete " " and "]".
>
> > <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>
>
> Interesting. =A0When I cut and paste your code fragment into a
> stylesheet and run it on your input, both xsltproc and Saxon give me
>
> =A0<FCTR_2>0.04200</FCTR_2>
>
> not
>
> =A0<FCTR2>0.04200</FCTR2>
>
> Similar tests show that the XSLT processors in Safari, Opera,
> and Firefox all produce "FCTR_2" not "FCTR2" from the input you
> describe.
>
> Two questions: =A0
>
> (1) Are you sure that the code you quote is actually the code that is
> producing the output you quote? =A0Try replacing
>
> =A0 <xsl:variable name=3D"tag"
> =A0 =A0select=3D"translate(translate(rateCode/text(),'[ ]','_'),'.','__')=
"/>
>
> with
>
> =A0 <xsl:variable name=3D"tag" select=3D"hi_mom"/>
>
> to see if your output is still <FCTR2>0.04200</FCTR2> or changes to
> <hi_mom>0.04200</hi_mom>.
>
> (2) If your output does change, indicating that the code you
> quote really is the code doing the work, then I become curious:
> What XSLT processor are you using?
>
> HTH
>
> Michael Sperberg-McQueen
>
> --
> ****************************************************************
> * C. M. Sperberg-McQueen, Black Mesa Technologies LLC
> *http://www.blackmesatech.com
> *http://cmsmcq.com/mib
> *http://balisage.net
> ****************************************************************

Ok, a light bulb has finally gone off thanks to your detailed
explanation.  I appreciate the effort in your reply.  I was confused a
bit regarding which of my tests produced the FCTR2 without the
underscore.  XMLSpy's default processor, Microsoft's MSXML and Xalan
all produce FCTR_2 using the example given.  I was doing some testing
with multiple spaces using the same argument 2 and it produced FCTR2.
Sorry for the confusion, but I understand the how and why now.  Thanks.


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