TIBCO XPath Tips

Comment

{-- comment --}

starts-with

scenario: check if any value of “numberPrefix” element starts with a specific value

GetNumberList:

<root>
  <numberPrefix>...</numberPrefix>
  <numberPrefix>...</numberPrefix>
……
</root>
count($GetNumberList/root[numberPrefix[starts-with(., 'Valid Value')]]) > 0

Subtract Map

(取出不存在Result List的accountNumber)

$Start/root/accountInfo/accounts[not(accountNumber=$Result/accounts/accountNumber)]

sum

(計算dueDate<=前一天的amount總和)

sum($invoice/invoiceInfos/InvoiceInfo[dueDate[tib:compare-dateTime(.,tib:add-to-dateTime(current-dateTime(),0,0,-1,0,0,0))<=0]]/amount)

Extract Node without Namespaces

<xsl:value-of select="*:Envelope/*:Body/*:user/*:name"/>

Sort

在 for-each→點選Add Child→Statement Type: Sort→設定 Ordering, Data-Type…→Ok

Remove duplicate Data

Method 1: Using Grouping

http://tutorialspedia.com/tibco-for-each-group-tutorial-removing-duplicate-data/

Method 2: Sort→Using position(), 取第一筆及所有與前一筆不同的資料 (以此來去除重覆值)

$idx = position()
($idx=1) or (current()/XXX != $sort/...[$idx - 1]/XXX)

取出第一筆符合條件的資料

<root>
  <response>
    <services>
      <entity>Offer</entity>
      <attributes>
        <name>Type</name>
        <value>P</value>
      </attributes>
      <attributes>
        ......
      </attributes>
    </services>
    <services>
      ......
    </services>
  </response>
</root>
$root/response/services[.[entity='Offer']/attributes[name='Type']/value='P'][1]

tokenize

判斷是否符合條件

判斷 services.entity 是否為 Offer or Reward or Adjust
count($root/response/services[entity=tib:tokenize('Offer,Reward,Adjust',',')]) > 0

判斷是否為數字

string(number($root/response/services/count)) = 'NaN' → 非數字
not(number($root/response/services/count))

Reference

http://tibco-middleware.blogspot.tw

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s