1

Please help me with this xslt transformation.

Source Xml

<xml>
 <test>This is a <bold>sample</bold> description. Please help me with a sample</text>
</xml>

Expected Output: This is a sample description. Please help me with a sample

I just need to make bold only the specified text by the xml markup.

Thank you

2
  • what do you want for your output format ? html ? rtf ? ps ? ... Commented Jun 11, 2010 at 18:17
  • Good Question (+1). See my answer for a complete solution. Commented Jun 11, 2010 at 18:28

1 Answer 1

2

This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="text">
   <p>
     <xsl:apply-templates/>
   </p>
 </xsl:template>

 <xsl:template match="bold">
   <b><xsl:apply-templates/></b>
 </xsl:template>
</xsl:stylesheet>

when applied against the provided XML document:

<xml>
 <text>This is a <bold>sample</bold> description. Please help me with a sample</text>
</xml>

produces the desired result in HTML:

 <p>This is a <b>sample</b> description. Please help me with a sample</p>
Sign up to request clarification or add additional context in comments.

1 Comment

@m00sila: Glad it works. In such cases you are expected to accept the answer (click on the check mark that must be displayed somewhere near the answer). :)

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.