I\'d like to trim the leading whitespace inside p tags in XML, so this:
Hey, italics and italics!
I would do something like this:
This will strip left space from the initial node child of a element, if it is a text node. It will not strip space from the first text node child, if it is not the first node child. E.g. in
Hey there
I intentionally avoid stripping the space from the front of 'there', because that would make the words run together when rendered in a browser. If you did want to strip that space, change the match pattern to
match="p/text()[1]"
If you also want to strip trailing whitespace, as your title possibly implies, add these two templates:
The definitions of the left-trim and right-trim templates are at Trim Template for XSLT (untested). They might be slow for documents with lots of s. If you can use XSLT 2.0, you can replace the call-templates with
and
(Thanks to Priscilla Walmsley.)