XSLT – count whitespace using regular expression

I have a xml like follows,

<doc>
    <p>  first sentence</p>
    <p>second sentence</p>
    <p>          third sentence</p>
</doc>

I need to count the number of spaces (white space) before start the text in <p> nodes.
So in above example 2,0,10 should be return.

I can use count() function to get the count and separate the white space string using tokenize() but my problem is write a regular expression to get the needed white space. How can I write a regular expression to get those white spaces?


Source: xml

Leave a Reply