[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: translating and commenting punctuation [XSLT1.0]

Subject: Re: translating and commenting punctuation [XSLT1.0]
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Thu, 24 Feb 2011 13:18:39 +0100
Re:  translating and commenting punctuation [XSLT1.0]
pankaj.c@xxxxxxxxxxxxxxxxxx wrote:
Hello everybody,

I am trying to translate "," in text to new line while keeping a copy of
it in comment. Some thing like below:

XML
===

<mytext>xxxx, yyyy, zzzzz, ttttt</mytext>

Output Required
==========

<mytext>xxxx<!--,-->
  yyyy<!--,-->
  zzzzz<!--,-->
  ttttt</mytext>

Your subject says XSLT 1.0 so here is an XSLT 1.0 approach:


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

<xsl:template name="replace">
<xsl:param name="text"/>
<xsl:param name="char" select="','"/>
<xsl:choose>
<xsl:when test="not(contains($text, $char))">
<xsl:value-of select="$text"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before($text, $char)"/>
<xsl:comment>
<xsl:value-of select="$char"/>
</xsl:comment>
<xsl:text>&#10;</xsl:text>
<xsl:call-template name="replace">
<xsl:with-param name="text" select="substring-after($text, $char)"/>
<xsl:with-param name="char" select="$char"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


  <xsl:template match="mytext">
    <xsl:copy>
      <xsl:call-template name="replace">
        <xsl:with-param name="text" select="."/>
      </xsl:call-template>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
--

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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.