Text replacement

Discussion in 'XML' started by Markus, Dec 16, 2005.

  1. Markus

    Markus Guest

    Hello,

    I have a question concerning XSL and text replacement. I have the
    following simple XML structure:
    <data>
    <element>ř{Dž</element>
    </data>

    Now I want to transform this to:
    <data>
    <element>+++</element>
    </data>

    So what I want to do is to replace parts of the form &#<number>; with a
    special character (e.g. +). Of course I want to do this in attribute
    values too and it might be possible that a string is mixed:
    řab{cdefDž will be transformed to +ab+cdef+. Is it
    possible to do this in XSL with
    a) no self written extension (only standards)
    b) the usage of XSL 1.0 (no absolute necessary)?

    Regards
    Markus
     
    Markus, Dec 16, 2005
    #1
    1. Advertising

  2. Read about the translate() function.

    Cheers,
    Dimitre Novatchev

    "Markus" <> wrote in message
    news:...
    > Hello,
    >
    > I have a question concerning XSL and text replacement. I have the
    > following simple XML structure:
    > <data>
    > <element>ř{Dž</element>
    > </data>
    >
    > Now I want to transform this to:
    > <data>
    > <element>+++</element>
    > </data>
    >
    > So what I want to do is to replace parts of the form &#<number>; with a
    > special character (e.g. +). Of course I want to do this in attribute
    > values too and it might be possible that a string is mixed:
    > řab{cdefDž will be transformed to +ab+cdef+. Is it
    > possible to do this in XSL with
    > a) no self written extension (only standards)
    > b) the usage of XSL 1.0 (no absolute necessary)?
    >
    > Regards
    > Markus
    >
     
    Dimitre Novatchev, Dec 16, 2005
    #2
    1. Advertising

  3. "Markus" <> wrote in message
    news:...
    > Hello,
    >
    > I have a question concerning XSL and text replacement. I have the
    > following simple XML structure:
    > <data>
    > <element>ř{Dž</element>
    > </data>
    >
    > Now I want to transform this to:
    > <data>
    > <element>+++</element>
    > </data>
    >
    > So what I want to do is to replace parts of the form &#<number>; with a
    > special character (e.g. +). Of course I want to do this in attribute
    > values too and it might be possible that a string is mixed:
    > řab{cdefDž will be transformed to +ab+cdef+. Is it
    > possible to do this in XSL with
    > a) no self written extension (only standards)
    > b) the usage of XSL 1.0 (no absolute necessary)?



    Do you want to replace all *character references* with special characters,
    or do you just want to replace some *characters*?

    By the time the XML source gets to the XSLT processor, all traces of
    character references are gone; all that is left are UTF-8 characters. This
    means that it is not possible to determine whether a character was in the
    form of the character reference in the source, or just a character.

    Having said that, if you have a subset of characters that you want to
    replace with some other character, you can use the translate() function
    (http://www.w3.org/TR/xpath#function-translate). For example:
    translate('string to replace characters in','abcdef','+') returns the string
    "string to r+pl+++ +h+r++t+rs in".


    // Magnus
     
    Magnus Henriksson, Dec 16, 2005
    #3
  4. "Magnus Henriksson" <> wrote in message
    news:dnu21q$j9p$...

    That should of course be: translate('string to replace characters
    in','abcdef','++++++').


    // Magnus
     
    Magnus Henriksson, Dec 16, 2005
    #4
  5. Markus

    Markus Guest

    Thanks for the information. I just didn't know that all character
    references have been resolved, when the XML source gets to the XSLT
    processor.

    Markus
     
    Markus, Dec 16, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexander Schmolck

    re.sub replacement text \-escapes woe

    Alexander Schmolck, Feb 13, 2004, in forum: Python
    Replies:
    4
    Views:
    376
    Alexander Schmolck
    Feb 14, 2004
  2. Hal Vaughan
    Replies:
    9
    Views:
    431
    James
    Dec 26, 2007
  3. Robert Mark Bram

    xml parsing and text replacement

    Robert Mark Bram, Feb 29, 2004, in forum: ASP General
    Replies:
    3
    Views:
    234
    Robert Mark Bram
    Mar 1, 2004
  4. Thomas Pierce
    Replies:
    6
    Views:
    125
    Jeremy McAnally
    Feb 18, 2008
  5. Phrogz
    Replies:
    1
    Views:
    108
    Martin Honnen
    Oct 31, 2006
Loading...

Share This Page