我们可以使用在BizTalk中执行操作的脚本(xslt)来解决这个问题。具体方法如下:
以下是实现方案中的示例代码:
// C# Script (enter as Script functoid containing this code)
public string GetFirstMatch(string input, string priori)
{
// split priority list by char represented here by ";"
string[] priList = priori.Split(';');
// load input xml to a document
XmlDocument doc = new XmlDocument();
doc.LoadXml(input);
// XPath to get all the rows
XmlNodeList nodes = doc.SelectNodes("//my:Record");
// Loop through all the rows
foreach (XmlNode node in nodes)
{
// get column value of row
string colVal = node.SelectSingleNode("my:Column").InnerText;
// perform matching
if (priList.Contains(colVal))
{
// select the first matching row as Output
XmlNode outNode = node.Clone();
return outNode.OuterXml;
}
}
// no match found, return empty XML
return " ";
}
这样我们就成功将“BizTalk map - loop through items and choose the first row with a column value that matches a value in a priority list”问题以脚本方式进行了解决。