Search code examples
xmlxpathinfopath

"Double Eval" XPath expression has a trailing semicolon... Giving me fits


Running into trailing semicolon issues while using a "Double Eval" XPath expression in conjunction with MS InfoPath to capture the contents of repeating structures. I need to eliminate the trailing semicolon from the result. Here is the expression:

eval(eval(Repeater, 'concat(my:Node1DropDown, ";")'), "..")

The results of the above expression can be seen in "Node1Eval" in the below XML. The expression would be great except for the trailing semicolon in the result.

<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.4" productVersion="14.0.0" PIVersion="1.0.0.0" href="file:///C:\Documents%20and%20Settings\Chris\Local%20Settings\Application%20Data\Microsoft\InfoPath\Designer3\e2c7e5c6af2049e9\manifest.xsf" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?>
<my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-08-28T16:45:10" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us">
<my:Master_Section>
    <my:group2>
        <my:Repeater>
            <my:Node1DropDown>Lasers</my:Node1DropDown>
            <my:Node2DropDown>Lemon</my:Node2DropDown>
        </my:Repeater>
        <my:Repeater>
            <my:Node1DropDown>Sharks</my:Node1DropDown>
            <my:Node2DropDown>Apple</my:Node2DropDown>
        </my:Repeater><my:Repeater>
            <my:Node1DropDown>Monkeys</my:Node1DropDown>
            <my:Node2DropDown>Lemon</my:Node2DropDown>
        </my:Repeater>
    </my:group2>
    <my:Node1Eval>Lasers;Sharks;Monkeys;</my:Node1Eval>
    <my:Node2Eval>Lemon;Apple;Lemon;</my:Node2Eval>
</my:Master_Section>
</my:myFields>

I would guess that the addition of some logic relating to the position of the returned item could help eliminate the trailing semicolon.

The real crux of the issue is that the semi-colon is always there; I need the Node1Eval field to be empty until it actually has a value to display. If not then it will mess with a [text()] XPath expression test I am trying to run.


Solution

  • Denoting your

    eval(eval(Repeater, 'concat(my:Node1DropDown, ";")'), "..")

    by X, it would be

    substring(X, 1, string-length(X) - 1)

    giving eventually

    substring(eval(eval(Repeater, 'concat(my:Node1DropDown, ";")'), ".."); 1, string-length(eval(eval(Repeater, 'concat(my:Node1DropDown, ";")'), "..")) - 1)

    Update:
    If you search by "substring(eval(eval(", you can confirm that it is quite frequently used for repeating controls in Infopath, for ex., this discussion

    I need the Node1Eval field to be empty until it actually has a value to display

    In Infopath Designer, on your rule action (or default value), wherever you insert and edit your Xpath expression, press fx > double-click on Repeater > press Filter data... button and insert whtever condition you wish.
    For the case, of Node1DropDown being non-blank, it will probably result in

    eval(eval(Repeater[Node1DropDown != ""], 'concat(my:Node1DropDown, ";")'), "..")