xsl-list
[Top] [All Lists]

Re: [xsl] Transform symbol to element

2009-11-11 06:36:58
Selvaganesh wrote:

This is possible to convert the quote symbol to xml elements?

If anybody know the way please share me, below placed my input file format
and required output format.
Input XML:

<p>This is the sample of double quote starting “the double publication”
ended</p>
<p>This is the sample of single quote starting ‘the single publication’
ended</p>


Output XML:

<para>This is the sample of double quote starting <quote open="“"
close="”">the double publication</quote> ended</para>
<para>This is the sample of single quote starting <quote open="‘"
close="’">the single publication</quote> ended</para>

With XSLT 2.0 you can try it as follows:


  <xsl:template match="p">
    <para>
      <xsl:analyze-string select="." regex="(“)([^“]*)(”)|(‘)([^‘]*)(’)">
        <xsl:matching-substring>
          <quote open="{regex-group(1)}" close="{regex-group(3)}">
            <xsl:value-of select="regex-group(2)"/>
          </quote>
        </xsl:matching-substring>
        <xsl:non-matching-substring>
          <xsl:value-of select="."/>
        </xsl:non-matching-substring>
      </xsl:analyze-string>
    </para>
  </xsl:template>


--

        Martin Honnen
        http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>