How to capitalize a string?

Hello Docentric,

I would like to ask if it is possible to use a function or write an Xpath expression that capitalizes a string? For example, in the data source I have the value “Purchase order”, but I would like to see “Purchase Order” on the generated document.

I see that there are two functions available in the Xpath editor, lowercase and uppercase, but neither of these functions meets my expectations.


MS Word’s built-in functions support ALL CAPS and SMALL CAPS, but these don’t help either. Is it possible to achieve this?

Hi Karin,

Unfortunately, the built-in MS Word functionality does not support this, but there is a solution to this problem with Docentric. It requires a bit of exercise and an in-depth understanding of the Xpath - but I’ll try to describe this on an example.

You will see three tagging elements in my example - the outer list element, a var element and a field element (1 ).

The list tagging element uses the string-split function to convert the value of the @DocumentTitle field into one or multiple instances, depending on the number of spaces it finds in it:

string-split(@DocumentTitle, true(), ' ')

Inside the list we find a var tagging element (2 ) which I named as title . As you will see in the attached template this element is bound to CurrentDataContext and thus stores (one or multiple) values of instances - I. e. groups of characters from the @DocumentTitle field separated by spaces.

The third element is the field that uses the following expression:

concat(upper-case(replace(var-element-value('title'), sub-string(var-element-value('title'), 2), '')), lower-case(sub-string(var-element-value('title'), 2)))

Let’s now analyze this expression bit by bit. Going from the back of it, the var element value is read (with the var-element-value function) from the memory. Next, by using the sub-string function, the first letter of this value is cut off and converted to lower-case, e. g. Invoice > nvoice or Title capitalized TEST > itle apitalized est

lower-case(sub-string(var-element-value('title'), 2))

Then we have to isolate and capitalize the first letter(s) of each value (word) of the current instance. We can do that easily with the replace function:

upper-case(replace(var-element-value('title') , sub-string(var-element-value('title'), 2), ''))

From the whole word, Docentric performs a replace of the value it finds starting at character number 2 of the same word. This part is then replaced with an empty string (removed) and capitalized with the upper-case function, e. g. capitalized - apitalized = C

Finally, both parts - the first character and the rest of the string - are joined back via the concat function.

You can find my test template attached. It’s a nice exercise to try and insert the elements and bindings into your template yourself, but if you find that time-consuming, you can just click the tag on the list element (3 ), copy all the elements and bindings, and paste them into the template you are working on.

I hope you find our solution helpful - please let me know what you think.