xsl-list
[Top] [All Lists]

Re: [xsl] Usage of XSLT in the field of text replacement.

2008-10-10 01:06:32
Hi Mukul and Ken, I am extremely happy with the analysis provide by you people. Actually I want to know whether we can use XSLT in the field to string manipulation with the help of third file (user define). Right now we are doing this kind of process by Perl which is a good for string manipulation.

An error (regular expression must not be one that matches a zero length string) is occurring while testing the xslt in the following line
<xsl:analyze-string select="."  regex="{$regex-pattern}">

> 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.

expressions. I hope the OP will clarify this.
I think I must share my experience of string manipulation by Perl which will help you people to understand the concept. What we do in Perl is simple as follows:
1. read temp.ini and store it as an array
2. read a.xml file
3. apply 'FOR' loop and took each line in an array variable ($lineItem)
4. split variable ($lineItem) by | separator into $searchItem and $replaceItem
5. Search $searchItem in the input file (a.xml) and replace it with $replaceItem in the output file

> If there are sensitive regular expression characters in those values the results may not be > as desired.

You are right. My solution assumed that the old strings should be
regular expressions. For the example posted by the OP, I had to escape
the [ & ] characters. Escaping all possible escape characters could be
tedious with my solution.
For this purpose we replace these escape characters within $searchItem. (in this example [ & ] will be replaced by \[ & \]

> 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,

As suggested by you, the OP could consider having old string values as
regular expressions. Then he can reuse most of the code I posted.
I want to use it as a string not as regular expression. Is something like this kind of concept (<xsl:variable name="regex-pattern" select="tokenize($replacement-data, '|')"/>


> There are so many possible ways to approach the solution based on what the
> original poster wanted that I felt his request was unclear.

You are correct. Actually, my intention to post this solution was to
showcase, that XSLT 2.0 is capable enough to solve this kind of
problem and we can use a facility like, xsl:analyze-string.

I did not intend to write some code, that the OP can use out of the
box. He has to finalize certain constraints, and think some ideas of
his own too.
I want to explore the usage of XSLT and thinking that upto what extend it is helpful to substitute of Perl. Thanks for the effort done by you, once again!!!


--~------------------------------------------------------------------
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>