Home > Blockchain >  xQuery return dynamic value if element is empty
xQuery return dynamic value if element is empty

Time:10-12

I'm having the following request message:

<POORDERLIN>    
    <POLINESCHD>
        <DATETIME  qualifier="NEEDDELV"  type="T"  index="1">
            <YEAR>2022</YEAR>
            <MONTH>09</MONTH>
            <DAY>13</DAY>
            <HOUR>15</HOUR>
            <MINUTE>11</MINUTE>
            <SECOND>50</SECOND>
            <SUBSECOND>0000</SUBSECOND>
            <TIMEZONE> 0200</TIMEZONE>
        </DATETIME> 
    </POLINESCHD>
</POORDERLIN>

Sometimes this request message has empty year, month and day values. What I would like is when these elements are empty then fill in the current 'year', 'month' or 'day'.

What I tried:

  if data($POORDERLIN/POLINESCHD[1]/DATETIME/YEAR="") then (
   data($POORDERLIN/POLINESCHD[1]/DATETIME/YEAR="2022")
   )
   else ( 
     data($POORDERLIN/POLINESCHD[1]/DATETIME/YEAR)
   )

The problem with this method is that year is hardcoded and instead I would like to have a dynamic current year value. The same goes for 'month' and 'day'

How will I be able to achieve what I'm looking for?

CodePudding user response:

You can obtain the current year, month, and day from fn:current-date().

Though, not sure the example code you posted is going to do what you want. It will need to be adjusted to something more like:

if $POORDERLIN/POLINESCHD[1]/DATETIME/YEAR/data() then 
  $POORDERLIN/POLINESCHD[1]/DATETIME/YEAR/data()
else
  year-from-date(current-date())
  • Related