This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: char replacement


Not sure I quite understand what you mean by "(Unicode 'xD')".

The XML 1.0 spec section 2.11 says that all the CR or CRLF in your
source file will be converted to LF. This applies equally to
source input and stylesheet XML documents.

The only way to actually get the CR preserved in the input or
stylesheet document is to include the CR as a character reference
in the source XML i.e. 
 (see XML 1.0 spec section 4.1). So given
your example, I'm surprised you found any CR at all.

On a more general note, a recursive template it the usual way to handle
the sort of replacement you seek. The template processes the first
occurrence
of the pattern, then, if there are more occurrences, calls itself to
process the remainder. Finally the template returns the combination of
the portion of the string it has processed and the results of the
recursive call.

Regards
Michael


> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Philippe
> Figon
> Sent: Thursday, 9 May 2002 2:19 PM
> To: XSL-List@lists.mulberrytech.com
> Subject: [xsl] char replacement
>
>
> Hellolinefeed
>
> I am trying to write a stylesheet that could replace all the
> carriage return
> (CR) characters (Unicode 'xD') in the text() node of an element with
> something else.
> Let's put it simple ! I have an element named 'screen' with some
> text within
> and I'd wish to put something like ~\\ at the end of each line (LaTeXing
> isn't it ?):
> <screen>
> agdh djdjdkk
> whjjd kdopd
> shdm gfjkmd
> hdjdj kkdddl
> </screen>
>
> should become :
>
>
> agdh djdjdkk~\\
> whjjd kdopd~\\
> shdm gfjkmd~\\
> hdjdj kkdddl~\\
>
> I wrote a stylesheet like this :
> (the output method is 'text')
>
> <xsl:template match="screen">
>     <xsl:variable name="texto"><xsl:value-of
> select="substring-before(.,xD)"/></xsl:variable>
>   <xsl:value-of select="concat($texto,'~\\')"/>
> </xsl:template>
>
> That works for the first 'xD' appearing but I can't find how to
> make it work
> recursively for the whole content of the 'screen' text. (XSLT is
> not the best
> thing to make strings replacements, I guess ;-) )
>
> Could anyone help ?
>
> Cheers
>
> Phil
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]