Re: [xsl] Need an elegant (succinct) XPath expression to decode a 3-character field

Subject: Re: [xsl] Need an elegant (succinct) XPath expression to decode a 3-character field
From: "Norm Tovey-Walsh ndw@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 26 Jan 2024 15:28:45 -0000
"Roger L Costello costello@xxxxxxxxx"
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> writes:
> The value is encoded. I need an XPath expression which decodes it.
>
> If the first digit is non-zero, then the decoding is: the first two digits,
decimal point, the last digit.
>
> In the example above, the first digit is 1, so it is decoded to 15.2
>
> 152 -> decode -> 15.2
>
> (the aircraft's required performance is 15.2 NM).
>
> If the first digit is zero, then the decoding is: the third digit
> represents the number of places to the right of the decimal point,
> e.g.,
>
> 010 -> decode -> 1
> 011 -> decode -> 0.1
> 012 -> decode -> 0.01
b&

Thatbs a strange encoding, and I donbt see from the examples how it can
usefully represent arbitrary numbers. But this seems to work for the
examples you provided, assuming the RNP is the value of the context
item:

  if (starts-with(., '0'))
  then
    let $shift := xs:integer(substring(., 3, 1))
    return
      xs:double(substring(., 2, 1)) div math:pow(10, $shift)
  else
    substring(., 1, 2) || '.' || substring(., 3)}">

                                        Be seeing you,
                                          norm

--
Norm Tovey-Walsh <ndw@xxxxxxxxxx>
https://norm.tovey-walsh.com/

> The people I distrust most are those who want to improve our lives but
> have only one course of action.--Frank Herbert

[demime 1.01d removed an attachment of type application/pgp-signature which had a name of signature.asc]

Current Thread