[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Need an elegant (succinct) XPath expression to decode

Subject: Need an elegant (succinct) XPath expression to decode a 3-character field
From: "Roger L Costello costello@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 26 Jan 2024 15:00:49 -0000
 Need an elegant (succinct) XPath expression to decode
Hi Folks,

My XML document contains an element named RNP (Required Navigation
Performance, which is the required performance of an aircraft, measured in
nautical miles).

Its value is three digits, e.g.,

<RNP>152</RNP>

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
013 -> decode -> 0.001
014 -> decode -> 0.0001
015 -> decode -> 0.00001
016 -> decode -> 0.000001
017 -> decode -> 0.0000001
018 -> decode -> 0.00000001
019 -> decode -> 0.000000001

I created an XPath expression which seems to do the decoding correctly. See
below. It is an awful, brute force solution. Is there an elegant (succinct)
solution?

if (substring(RNP,1,1) ne '0') then
concat(substring(RNP,1,2),'.',substring(RNP,3,1))
else if (substring(RNP,1,1) eq '0') then
           if (substring(RNP,3,1) eq '0') then substring(RNP,2,1)
           else if (substring(RNP,3,1) eq '1') then
concat('0.',substring(RNP,2,1))
           else if (substring(RNP,3,1) eq '2') then
concat('0.0',substring(RNP,2,1))
           else if (substring(RNP,3,1) eq '3') then
concat('0.00',substring(RNP,2,1))
           else if (substring(RNP,3,1) eq '4') then
concat('0.000',substring(RNP,2,1))
           else if (substring(RNP,3,1) eq '5') then
concat('0.0000',substring(RNP,2,1))
           else if (substring(RNP,3,1) eq '6') then
concat('0.00000',substring(RNP,2,1))
           else if (substring(RNP,3,1) eq '7') then
concat('0.000000',substring(RNP,2,1))
           else if (substring(RNP,3,1) eq '8') then
concat('0.0000000',substring(RNP,2,1))
           else concat('0.00000000',substring(RNP,2,1))
      else ''

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.