5

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.

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.