Page 1 of 1

XQuery IF THEN ELSE in CSS oxy_xpath

Posted: Tue Aug 15, 2023 11:57 pm
by dsmith1690
I'm attempting to use the "oxy_xpath" functionality in CSS with an XQuery that retrieves the list item target of a cross-reference and outputs the list item number in a format that reflects the list type. I have everything working as desired except for the series of IF THEN ELSE statements and I can't get even one of those to work. So this is basically what I want in the CSS rule xpath:

Code: Select all

INTXREF[DEST = "LST-ITM"]{
content: oxy_xpath("let\
        $targetID := @REFID,\
        $myTargetList-Item := /descendant::LIST/LST-ITM[@ID = $targetID]/@ID,\
        $myTargetList-Type := /descendant::LIST[LST-ITM[@ID = $targetID]]/@ENUMTYPE,\            
        if(contains($myTargetList-Type, 'LOWERALPHA')),\
        then format-integer(index-of(/descendant::LIST[LST-ITM/@ID = $targetID]/LST-ITM/@ID, $myTargetList-Item), 'a'),\    
        else concat('List type ', $myTargetList-Type, 'not supported')");
}
Somewhere in that there's a syntax error that I can't identify (not experienced in XQuery). Apart from that the three variables ($targetID, $myTargetList-Item, and $myTargetList-Type all work as expected; the formatting of the calculated integer works correctly. But I can't get the IF THEN ELSE correct, must less the additional ones I'll need to additional list types.
Any help pointing me in the right direction will be greatly appreciated. I'm pasting a sample XML doc below for reference.

Code: Select all

<ROOT>
    <LIST ENUMTYPE="LOWERALPHA" TYPE="ORDERED">
        <LST-ITM ID="L1I1">
            <PTXT>List 1 - List item 1</PTXT>
        </LST-ITM>
        <LST-ITM ID="L1I2">
            <PTXT>List 1 - List item 2</PTXT>
        </LST-ITM>
        <LST-ITM ID="L1I3">
            <PTXT>List 1 - List item 3</PTXT>
        </LST-ITM>
    </LIST>
    <P>Paragraph</P>
    <LIST ENUMTYPE="ARABICNUM" TYPE="ORDERED">
        <LST-ITM ID="L2I1">
            <PTXT>List 2 - List item 1</PTXT>
        </LST-ITM>
        <LST-ITM ID="L2I2">
            <PTXT>List 2 - List item 2</PTXT>
        </LST-ITM>
        <LST-ITM ID="L2I3">
            <PTXT>List 2 - List item 3</PTXT>
        </LST-ITM>
    </LIST>
    <P>This reference is to List 1 Item 2: <INTXREF DEST="LST-ITM" REFID="L1I2"/></P>
    <P>This reference is to List 2 Item 3: <INTXREF DEST="LST-ITM" REFID="L2I3"/></P>
</ROOT>

Re: XQuery IF THEN ELSE in CSS oxy_xpath

Posted: Fri Aug 18, 2023 8:39 am
by dsmith1690
Here's the answer:

Code: Select all

INTXREF[DEST = "LST-ITM"]{
    font-weight:bold;
    content: oxy_xpath("let\
      $targetID := @REFID,\
      $myTargetList-Item := /descendant::LIST/LST-ITM[@ID = $targetID]/@ID,\
      $myTargetList-Type := /descendant::LIST[LST-ITM[@ID = $targetID]]/@ENUMTYPE\
      return\
      if (contains($myTargetList-Type, 'LOWERALPHA'))\
      then format-integer(index-of(/descendant::LIST[LST-ITM/@ID = $targetID]/LST-ITM/@ID, $myTargetList-Item), 'a')\
      else if (contains($myTargetList-Type, 'UPPERALPHA'))\
        then format-integer(index-of(/descendant::LIST[LST-ITM/@ID = $targetID]/LST-ITM/@ID, $myTargetList-Item), 'A')\
        else if (contains($myTargetList-Type, 'LOWERROMAN'))\
            then format-integer(index-of(/descendant::LIST[LST-ITM/@ID = $targetID]/LST-ITM/@ID, $myTargetList-Item), 'i')\
            else if (contains($myTargetList-Type, 'UPPERROMAN'))\
                then format-integer(index-of(/descendant::LIST[LST-ITM/@ID = $targetID]/LST-ITM/@ID, $myTargetList-Item), 'I')\
                else index-of(/descendant::LIST[LST-ITM/@ID = $targetID]/LST-ITM/@ID, $myTargetList-Item) ");
}

Re: XQuery IF THEN ELSE in CSS oxy_xpath

Posted: Fri Aug 18, 2023 8:43 am
by Radu
Hi,
Thanks for updating the thread to post the solution.
Regards,
Radu