Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

translating one string pattern into another string pattern using XSLT

Tags:

xml

xslt

xpath

I have my source XML like below

<contents>
  <content>AuthorInformation</content>
  <content>PersonInformation</content>
  <content>PersonPersonalInformation</content>
  <content>GurdianDetails</content>
</contents>

I would like to transform above XML into

<contents>
  <content>Author Information</content>
  <content>Person Information</content>
  <content>Person Personal Information</content>
  <content>Gurdian Details</content>
</contents>

wherever in source xml file content element data is having upper case letter I would like to prefix space inbetween. Can I have the XSLT 2.0 sample how I can achieve this.

like image 460
Laxmikanth Samudrala Avatar asked Oct 10 '22 01:10

Laxmikanth Samudrala


1 Answers

Use a template like this:

<xsl:template match="text()">
    <xsl:value-of select="replace(., '([a-z])([A-Z])', '$1 $2')"/>
</xsl:template>

This generically performs the rule for all text content in the input. You could easily make this more specific (if there are other elements that you don't want to translate). The replace function is the key point.

like image 134
Wayne Avatar answered Oct 19 '22 03:10

Wayne