xslt 2.0 - Replace nbsp with another tag -


in xml file have tag this(within p tags have nbsp;)

now want replace nbsp tag(as example within p tag want insert tag called s <s/>)

is possible do.please help

first note tree on xslt operates never contains character or entity reference, contains unicode character. match on , replace unicode character element can use analyze-string:

<xsl:stylesheet   xmlns:xsl="http://www.w3.org/1999/xsl/transform"   version="2.0">  <xsl:template match="@* | node()">   <xsl:copy>     <xsl:apply-templates select="@* , node()"/>   </xsl:copy> </xsl:template>  <xsl:template match="p//text()">   <xsl:analyze-string select="." regex="&#160;">     <xsl:matching-substring>       <s/>     </xsl:matching-substring>     <xsl:non-matching-substring>       <xsl:value-of select="."/>     </xsl:non-matching-substring>   </xsl:analyze-string> </xsl:template>  </xsl:stylesheet> 

that way input document like

<?xml version="1.0" encoding="utf-8"?> <!doctype doc [   <!entity nbsp "&#160;"> ]> <doc>   <p>this paragraph non-breaking space &nbsp; before sub text.</p> </doc> 

is transformed result document

<?xml version="1.0" encoding="utf-8"?><doc>   <p>this paragraph non-breaking space <s/> before sub text.</p> </doc> 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -