XSLT - Replacing new line with br tag -


is there way replace new line br tag in xslt 1.0? tried 
 
 &#x0a still can not match new line.

here code:

<xsl:template name="headline">   <xsl:if test="$gheadline">     <xsl:element name="lnv:headline">       <xsl:element name="lnvxe:hl1">         <xsl:variable name="vstring">           <xsl:choose>             <xsl:when test="contains($gheadlinecaps,'entert@inment.com')">               <xsl:variable name="vleftstring" select="substring-before($gheadline,'@')"/>               <xsl:variable name="vrightstring" select="substring-after($gheadline,'@')"/>             <xsl:value-of select="concat($vleftstring,' @',$vrightstring)"/>              </xsl:when>             <xsl:otherwise>               <xsl:value-of select="$gheadline" />             </xsl:otherwise>           </xsl:choose>         </xsl:variable>         <xsl:value-of select="translate($vstring,'&#x0a;','&lt;br/&gt;')"/>        </xsl:element>     </xsl:element>   </xsl:if> </xsl:template> 

here input:

 agony  train derails, dozens hurt in smoky chaos  mayor, gov no-shows after latest mta fail  exclusive motorman tells news story   don't care  prez 'ok' health bill flops   met loss  pitcher dead @ 51 

this desired output:

 agony<br/>  train derails, dozens hurt in smoky chaos<br/>  mayor, gov no-shows after latest mta fail<br/>  exclusive motorman tells news story<br/>  <br/>  don't care<br/>  prez 'ok' health bill flops<br/>  <br/>  met loss<br/>  pitcher dead @ 51<br/> 

thanks!

if use library exslt can write as

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform"     xmlns:str="http://exslt.org/strings"     exclude-result-prefixes="str"     version="1.0">      <xsl:import href="http://exslt.org/str/functions/replace/str.replace.template.xsl"/>      <xsl:template match="text">         <xsl:copy>             <xsl:call-template name="str:replace">                 <xsl:with-param name="string" select="."/>                 <xsl:with-param name="search" select="'&#10;'"/>                 <xsl:with-param name="replace"><br/></xsl:with-param>             </xsl:call-template>         </xsl:copy>     </xsl:template>  </xsl:stylesheet> 

and transforms

<text> agony     train derails, dozens hurt in smoky chaos     mayor, gov no-shows after latest mta fail     exclusive motorman tells news story      don't care     prez 'ok' health bill flops      met loss     pitcher dead @ 51</text> 

into

<text> agony<br/>    train derails, dozens hurt in smoky chaos<br/>    mayor, gov no-shows after latest mta fail<br/>    exclusive motorman tells news story<br/>    <br/>    don't care<br/>    prez 'ok' health bill flops<br/>    <br/>    met loss<br/>    pitcher dead @ 51</text> 

Comments

Popular posts from this blog

javascript - Replicate keyboard event with html button -

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Web audio api 5.1 surround example not working in firefox -