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=" "> <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 " "> ]> <doc> <p>this paragraph non-breaking space 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
Post a Comment