w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to find a specific substring of text anywhere in my XML and select this text using XSLT

Using XSLT 2.0 you could use analyze-string on all text() nodes e.g.

<xsl:template match="text()">
  <xsl:analyze-string select="." regex="&#160;">
      <span class="highlight"><xsl:value-of
      <xsl:value-of select="."/>

You would then need to set up other templates to transform the remaining elements to HTML where you include the CSS or link to some CSS document defining something like

span.highlight { color: red; }

The span or similar wrapper element is necessary in my view as CSS does not allow you to style a single letter or word within a text node.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.