how to extract and trim xslt string value coming from a database

If you want to trim spaces or newline of a field value, you can use the normalize-space() function.

for example:

you have a field Summary in a certain table and one row has a value of

<h1>Women’s Soft Shell Battery Heated Jacket</h1>
Maximum heat with minimal effort

and you wanted to display the word “Maximum heat with minimal effort” text only. First you need to eliminate the h1 tag and its content and get or extract the text after the h1 tag which is the  ”Maximum heat with minimal effort”.

To do so, you may use substring-after() function.

substring-after(Summary,'&lt;/h1&gt;')
&lt;/h1&gt; is simply the equivalent of </h1> tag.

This tells the xsl to get the string after the </h1> tag.

Normally, there is a newline after the </h1> and it causes the text “Maximum heat with minimal effort” to display on the second line with an empty space above it, so we have to trim it to remove the extra space or newline.

you can use the normalize-space function as shown below.

<xsl:value-of select="normalize-space(substring-after(Summary,'&lt;/h1&gt;'))" disable-output-escaping="yes"/>
Leave a comment

0 Comments.

Leave a Reply


[ Ctrl + Enter ]

Netfirms Business Hosting Plan
Blog WebMastered by All in One Webmaster.
Plugin from the creators of Brindes Personalizados :: More at Plulz Wordpress Plugins