<xsl:function name="str:reverse" as="xs:string">
<xsl:param name="sentence" as="xs:string"/>
<xsl:sequence select="
if (contains($sentence, ' '))
then concat(str:reverse(
substring-after(
$sentence, ' ')),
' ',
substring-before($sentence, ' '))
else $sentence"/>
</xsl:function>This can be called from XPath: select="str:reverse('DOG BITES MAN')".