I have this regex code that used to work in CF10 but since moving to Lucee, it no longer works. (The problem is not Lucee, it is the Regex, and Lucee just seems to be less forgiving...)
The code is:
<cfset ThisNode = #XMLSearch(xmlResponse,"//*[local-name()='price_quotes']/*[local-name()='price_quote'] [* = '#CanPost_ServiceRegion##xmldata.CanPost_service_code#' ]/count(preceding-sibling::*) + 1")#>
The variable in the middle could be USA.SP.AIR for the purpuse of testing: so
<cfset ThisNode = #XMLSearch(xmlResponse,"//*[local-name()='price_quotes']/*[local-name()='price_quote'] [* = 'USA.SP.AIR' ]/count(preceding-sibling::*) + 1")#>
The closes I get to something right is:
count(preceding-sibling:://*[local-name()='price_quotes']/*[local-name()='price_quote'] [* = 'USA.SP.AIR' ]) + 1
But it always returns 1, instead of the actual position +1...
Can someone point me in the right direction?
The test xml file could be:
<?xml version="1.0" encoding="UTF_8"?> <price_quotes xmlns="
http://www.canadapost.ca/ws/ship/rate_v2"><price_quote><service_code>USA.EP</service_code><service_link rel="service" href="
https://soa_gw.canadapost.ca:443/rs/ship/service/USA.EP?contract=004002000&country=US" media_type="application/vnd.cpc.ship.rate_v2+xml"/><service_name>Expedited Parcel USA</service_name><price_details><base>19.40</base><taxes><gst>0.00</gst><pst>0.00</pst><hst>0.00</hst></taxes><due>20.22</due><options><option><option_code>DC</option_code><option_name>Delivery confirmation</option_name><option_price>0</option_price></option></options><adjustments><adjustment><adjustment_code>FUELSC</adjustment_code><adjustment_name>Fuel surcharge</adjustment_name><adjustment_cost>0.82</adjustment_cost><qualifier><percent>4.25</percent></qualifier></adjustment></adjustments></price_details><weight_details/><service_standard><am_delivery>false</am_delivery><guaranteed_delivery>false</guaranteed_delivery><expected_transit_time>4</expected_transit_time><expected_delivery_date>2015_11_19</expected_delivery_date></service_standard></price_quote><price_quote><service_code>USA.PW.PAK</service_code><service_link rel="service" href="
https://soa_gw.canadapost.ca:443/rs/ship/service/USA.PW.PAK?contract=004002000&country=US" media_type="application/vnd.cpc.ship.rate_v2+xml"/><service_name>Priority Worldwide pak USA</service_name><price_details><base>63.32</base><taxes><gst>0.00</gst><pst>0.00</pst><hst>0.00</hst></taxes><due>65.06</due><options><option><option_code>DC</option_code><option_name>Delivery confirmation</option_name><option_price>0</option_price></option><option><option_code>SO</option_code><option_name>Signature option</option_name><option_price>0</option_price></option></options><adjustments><adjustment><adjustment_code>FUELSC</adjustment_code><adjustment_name>Fuel surcharge</adjustment_name><adjustment_cost>1.74</adjustment_cost><qualifier><percent>2.75</percent></qualifier></adjustment></adjustments></price_details><weight_details/><service_standard><am_delivery>false</am_delivery><guaranteed_delivery>false</guaranteed_delivery></service_standard></price_quote><price_quote><service_code>USA.PW.PARCEL</service_code><service_link rel="service" href="
https://soa_gw.canadapost.ca:443/rs/ship/service/USA.PW.PARCEL?contract=004002000&country=US" media_type="application/vnd.cpc.ship.rate_v2+xml"/><service_name>Priority Worldwide parcel USA</service_name><price_details><base>70.30</base><taxes><gst>0.00</gst><pst>0.00</pst><hst>0.00</hst></taxes><due>72.23</due><options><option><option_code>DC</option_code><option_name>Delivery confirmation</option_name><option_price>0</option_price></option><option><option_code>SO</option_code><option_name>Signature option</option_name><option_price>0</option_price></option></options><adjustments><adjustment><adjustment_code>FUELSC</adjustment_code><adjustment_name>Fuel surcharge</adjustment_name><adjustment_cost>1.93</adjustment_cost><qualifier><percent>2.75</percent></qualifier></adjustment></adjustments></price_details><weight_details/><service_standard><am_delivery>false</am_delivery><guaranteed_delivery>false</guaranteed_delivery></service_standard></price_quote><price_quote><service_code>USA.SP.AIR</service_code><service_link rel="service" href="
https://soa_gw.canadapost.ca:443/rs/ship/service/USA.SP.AIR?contract=004002000&country=US" media_type="application/vnd.cpc.ship.rate_v2+xml"/><service_name>Small Packet USA Air</service_name><price_details><base>16.23</base><taxes><gst>0.00</gst><pst>0.00</pst><hst>0.00</hst></taxes><due>16.23</due></price_details><weight_details/><service_standard><am_delivery>false</am_delivery><guaranteed_delivery>false</guaranteed_delivery></service_standard></price_quote><price_quote><service_code>
USA.TP</service_code><service_link rel="service" href="
https://soa_gw.canadapost.ca:443/rs/ship/service/USA.TP?contract=004002000&country=US" media_type="application/vnd.cpc.ship.rate_v2+xml"/><service_name>Tracked Packet _ USA</service_name><price_details><base>18.19</base><taxes><gst>0.00</gst><pst>0.00</pst><hst>0.00</hst></taxes><due>18.96</due><options><option><option_code>DC</option_code><option_name>Delivery confirmation</option_name><option_price>0</option_price></option></options><adjustments><adjustment><adjustment_code>FUELSC</adjustment_code><adjustment_name>Fuel surcharge</adjustment_name><adjustment_cost>0.77</adjustment_cost><qualifier><percent>4.25</percent></qualifier></adjustment></adjustments></price_details><weight_details/><service_standard><am_delivery>false</am_delivery><guaranteed_delivery>false</guaranteed_delivery><expected_transit_time>6</expected_transit_time><expected_delivery_date>2015_11_23</expected_delivery_date></service_standard></price_quote><price_quote><service_code>USA.XP</service_code><service_link rel="service" href="
https://soa_gw.canadapost.ca:443/rs/ship/service/USA.XP?contract=004002000&country=US" media_type="application/vnd.cpc.ship.rate_v2+xml"/><service_name>Xpresspost USA</service_name><price_details><base>30.60</base><taxes><gst>0.00</gst><pst>0.00</pst><hst>0.00</hst></taxes><due>33.43</due><options><option><option_code>DC</option_code><option_name>Delivery confirmation</option_name><option_price>0</option_price></option><option><option_code>SO</option_code><option_name>Signature option</option_name><option_price>0</option_price></option></options><adjustments><adjustment><adjustment_code>FUELSC</adjustment_code><adjustment_name>Fuel surcharge</adjustment_name><adjustment_cost>2.83</adjustment_cost><qualifier><percent>9.25</percent></qualifier></adjustment></adjustments></price_details><weight_details/><service_standard><am_delivery>false</am_delivery><guaranteed_delivery>true</guaranteed_delivery><expected_transit_time>3</expected_transit_time><expected_delivery_date>2015_11_18</expected_delivery_date></service_standard></price_quote></price_quotes>