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

Re: Usage of XSLT in the field of text replacement.

Subject: Re: Usage of XSLT in the field of text replacement.
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 09 Oct 2008 08:12:06 -0400
Re:  Usage of XSLT in the field of text replacement.
At 2008-10-09 10:43 +0530, Mukul Gandhi wrote:
Here is a 2.0 solution for this (let's say this file is test.xsl),

I think, Mukul, the original poster should be aware that with your proposed solution the "temp.ini" file must express the "old" string value as a regular expression and not a simple string.


I think a safer solution would be to use simple substring-before() and substring-after() in recursion ... when I considered what to post as a solution I felt the original poster did not necessarily have control over the "old" string values in the control file. If there are sensitive regular expression characters in those values the results may not be as desired.

Then again, the original poster may want the power of regular expressions in the control file, in which case what you have presented is almost complete, but it does not give access to any grouping parentheses when specifying the "new" string value. For example, had you used replace() instead of analyze string the original poster would get access to "$" in the replacement string.

There are so many possible ways to approach the solution based on what the original poster wanted that I felt his request was unclear. But if you just look on the face of it, then I think the strings in "temp.ini" are not expected to be regular expressions, in which case the use of either <xsl:analyze-string> or replace() would be out of place for fear of unexpected results.

Then again perhaps using a simple replace() to protect the old string and new string by escaping any sensitive regular expression characters brings your solution to the fore again. Determine which characters are regular-expression-sensitive, escape any found in the "old" string and "new" string, and then walk through the string as you have done with <xsl:analyze-string/>.

I hope this helps.

. . . . . . . . . . . Ken

...
  <xsl:variable name="regex-pattern" select="string-join(for $x in
$replacement-data return (if
(starts-with(substring-before($x,'|'),'[') and
ends-with(substring-before($x,'|'),']')) then
concat('\',substring(substring-before($x,'|'),0,string-length(substring-before($x,'|'))),'\]')
else substring-before($x,'|')),'|')" />
...
      <xsl:analyze-string select="."
                          regex="{$regex-pattern}">
...
temp.ini

1|ONE
2|TWO
3|THREE
50|FOUR
[text]|[TEXT]
...
On Wed, Oct 8, 2008 at 4:09 PM, J. S. Rawat <jrawat@xxxxxxxxxxxxxx> wrote:
> Hi
> Can xslt2.0 play a role in the field of text replacement. I want to
> transform an xml to another xml and want to replace some text as well. For
> that purpose I want to restore "find and replace" text in a separate file
> with pipe separated delimeter.



-- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video sample lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg Video course overview: http://www.youtube.com/watch?v=VTiodiij6gE G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

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.