Search code examples
xmlxpathbiztalkbiztalk-bam

BizTalk BAM - manually editing BTT XPath to return just the First instance of a Message Payload property?


We have a preference for using TPE for BAM tracking since it can be deployed independently of our orchestrations.

However, at one point in our process, we need to track a message payload property which has a 1:N relationship with the Root XML Element of the message.

Despite the 1:N relationship, extracting just the first value of this property will be sufficient for our tracking needs.

As usual, if we attempt to track this, then the following XLANG message is logged:

AmbiguousXPathException - The result set for the XPath expression ... 
contains more than a single node

We have tried to modify the BTT XPath directly to select just the first instance of this Property

I've tried

'XPath="//*[local-name()='Property' and namespace-uri()='{URI}' ...]/[1]'

but then get the error "Expression must evaluate to a node-set"

and more simply

'//Property[1]' and '//Property[position() = 1]'

Give no error, but this doesn't pull out my property either.

Lastly, can anyone explain the difference between the XPath and SomXPath in the BTT file?


Solution

  • It is like shooting in the dark without any XML document provided, but you may try this:

    (//*[local-name()='Property' and namespace-uri()='{URI}' ...])[1]
    

    It is a FAQ that //x[1] does't select one node, while (//x)[1] does.

    The first means: every element named x, that is the first child of its parent.

    The second means: the first element x in the document.