XQuery IF THEN ELSE in CSS oxy_xpath

Issues related to W3C XQuery.
dsmith1690
Posts: 12
Joined: Wed Sep 23, 2020 1:42 am

XQuery IF THEN ELSE in CSS oxy_xpath

Post 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>
dsmith1690
Posts: 12
Joined: Wed Sep 23, 2020 1:42 am

Re: XQuery IF THEN ELSE in CSS oxy_xpath

Post 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) ");
}
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: XQuery IF THEN ELSE in CSS oxy_xpath

Post by Radu »

Hi,
Thanks for updating the thread to post the solution.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply