Dylan
Dylan

Reputation: 427

Valid Val Names for Template Driven Extraction TDE

My question is how I can successfully apply a template to data that doesn't meet the XML specifications. I have incoming data with element names, values such as:

An example document, retrieved with fn:doc($uri):

{
"ID": "208455", 
"Type": "Deductions", 
"MONTH": "1", 
"2015 - Joe's": "14.10%", 
}

The part I would like to manipulate with my TDE is:

"2015 - Joe's": "14.10%"

Where the value itself is a string.

I would like to cast the value to a decimal, using a TDE template, by removing the "%" for example. This works when executed in query console:

let $s1:= "14.10%"

return fn:number(fn:replace($s1, "[^0-9.]", ""))

###
14.1 (float)

When executing the same chained functions inside the template however:

    <column>
      <name>value_2015</name>
      <scalar-type>string</scalar-type>
      <val>fn:number(fn:replace(2015 - Joe's, "[^0-9.], ""))</val>
      <nullable>true</nullable>
    </column>

I receive an Compile for Column value_2015='fn:replace(2015 - Joe's, "[^0-9.], "")' returns XDMP-BADCHAR: (err:XPST0003) Unexpected character found ''' (0x0027) error. I believe this to be because the field name begins with a number and contains a " ' " character, in violation of the XML specification over here.

Consequently, I tried wrapping the element reference with "":

      <column>
      <name>value_2015</name>
      <scalar-type>string</scalar-type>
      <val>fn:replace("2015 - Joe's", "[^0-9.], "")</val>
      <nullable>true</nullable>

but this of course returns another BADCHAR error: XDMP-BADCHAR: (err:XPST0003) Unexpected character found '"' (0x0022) since now we have quotation marks in the element reference.

How would I even go about fixing this? If I can't reference the elements, how would I replace them with valid XML element names? Do I have any options to like, escape the XML and tell the template to find a literal match for a given sequence of characters in the argument?

Upvotes: 0

Views: 56

Answers (1)

ehennum
ehennum

Reputation: 7335

Does it work to use node("2015 - Joe's") or text("2015 - Joe's") as the first argument to fn:replace()?

That should match the text value with a property name of "2015 - Joe's"

Upvotes: 1

Related Questions