BizTalk Working With XPath – XPath 1.0 Function Library Quick Reference

  • Sandro Pereira
  • Aug 29, 2009
  • 8 min read

Whether you are extracting a value in an Orchestration Expression shape or building a complex Custom XSLT map, XPath is the language of choice. However, remembering every function and its syntax can be challenging.

You can use XML Path Language (XPath) functions to refine XPath queries and enhance the programming power and flexibility of XPath.

This guide serves as your quick reference for the XPath 1.0 Function Library, the version supported by Microsoft BizTalk Server. The functions are divided into the following groups: Node Set, String, Boolean, and Number.

📝 One-Minute Brief

Mastering XPath 1.0 is essential for BizTalk developers to effectively use the xpath() function in Orchestrations and custom XSLT. This quick reference guide provides a categorized library of XPath 1.0 functions—including string manipulation, boolean logic, and node-set operations—to help you navigate XML structures, filter data, and perform calculations without the overhead of complex custom coding.

Node Set Functions

Node-set functions take a node-set argument. They return a node-set, or information about a particular node within a node-set. These functions are critical for identifying and counting elements within your XML messages.

Function: [number] last() – Returns a number equal to the context size of the expression evaluation context, that is, returns the index number of the last node in the set.

Function: [number] position() – Returns the position, or index number, of the node, relative to all the selected nodes in the node list.

Function: [number] count(node-set) – Returns the number of nodes in the node-set argument, that is, returns the number of nodes in a set (perfect for loop counting).

Function: [node-set] id(object) – Selects elements by their unique ID.

Function: [string] local-name(node-set?) – Returns the local part of the expanded name of the node in the node-set argument that is first in document order, that is, it returns the name of the node without the namespace prefix.

Function: [string] namespace-uri(node-set?) – Returns the namespace Uniform Resource Identifier (URI) of the expanded name of the node in the node-set argument that is first in document order.

Function: [string] name(node-set?) – Returns a string containing a QName representing the expanded name of the node in the node-set argument that is first in document order.

String Functions

String functions are used to evaluate, format, and manipulate string arguments, or to convert an object to a string. Since most EDI and XML data is string-based, these are your most frequent tools.

Function: [string] string(object?) – Converts an object to a string.

Function: [string] concat(string, string, string*) – Returns the concatenation of the arguments.

Function: [boolean] starts-with(string, string) – Returns true if the first argument string starts with the second argument string; otherwise returns false.

Function: [boolean] contains(string, string) – Checks whether the first argument string contains the second argument string. Returns true if the first string contains the second.

Function: [string] substring-before(string, string) – Returns the substring of the first argument string that precedes the first occurrence of the second argument string in the first argument string, or the empty string if the first argument string does not contain the second argument string.

Function: [string] substring-after(string, string) – Returns the substring of the first argument string that follows the first occurrence of the second argument string in the first argument string, or the empty string if the first argument string does not contain the second argument string.

Function: [string] substring(string, number, number?) – Returns the substring of the first argument starting at the position specified in the second argument and the length specified in the third argument.

Function: [number] string-length(string?) – Returns the number of characters in the string.

Function: [string] normalize-space(string?) – Returns the argument string with the leading, trailing, and repeating white spaces stripped.

Function: [string] translate(string, string, string) – Returns the first argument string with occurrences of characters in the second argument string replaced by the character at the corresponding position in the third argument string.

Boolean Functions

The XML Path Language (XPath) syntax supports Boolean functions that return strings or numbers, and can be used with comparison operators in filter patterns.

Function: [boolean] boolean(object) – Converts the argument to a Boolean.

Function: [boolean] not(object) – Returns true if the argument is false; otherwise false.

Function: [boolean] true() – Returns true.

Function: [boolean] false() – Returns false.

Function: [boolean] lang(string) – Returns true if the xml:lang attribute of the context node is the same as a sublanguage of the language specified by the argument string.

Number Functions

The XML Path Language (XPath) syntax supports Number functions that return strings or numbers and can be used with comparison operators in filter patterns.

Function: [number] number(object?) – Converts the argument to a number.

Function: [number] sum(node-set) – Returns the sum of all nodes in the node-set. Each node is first converted to a number value before summing.

Function: [number] floor(number) – Returns the largest integer that is not greater than the argument.

Function: [number] ceiling(number) – Returns the smallest integer that is not less than the argument.

Function: [number] round(number) – Returns an integer closest in value to the argument.

Pro-Tip: Using XPath in Orchestrations

In a BizTalk Orchestration, you can use these functions like this:

CountVariable = xpath(MyMessage, "count(//*[local-name()='Item'])");

XPath 1.0 might be an older standard, but it remains the reliable foundation for data movement in BizTalk. Keep this library handy to avoid writing unnecessary C# helper classes for simple XML logic.

Hope you find this helpful! If you liked the content or found it useful and would like to support me in writing more, consider buying (or helping to buy) a Star Wars Lego set for my son. 

Thanks for Buying me a coffe

Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

2 thoughts on “BizTalk Working With XPath – XPath 1.0 Function Library Quick Reference”

Leave a Reply

Your email address will not be published. Required fields are marked *

The Ultimate Cloud
Management Platform for Azure

Supercharge your Azure Cost Saving

Learn More
Turbo360 Widget

Back to Top