Clarification to replace the & symbol to & in xml using XSL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • radhakrishnanrs
    New Member
    • Nov 2008
    • 5

    Clarification to replace the & symbol to & in xml using XSL

    Hi all,

    Here, a xml file is not in proper format. I need to replace the "&" symbol to "&" under the attributes. Find below the sample xml file for glance:

    <root>
    <child1>
    <child2 attribute1="tes t&test">Testing </child2>
    <child1>
    </root>

    Let me know how to resolve this instance. I need output like -- attribute1="tes t&amp;test" --. I need to replace "&" symbol using the XSL.

    Thanks
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    if your parser doesn't complain on the xml you can use the translate() function. but a correct working parser should give you an "undefined entity" error. in this case you have to change the & either by hand or by a script. maybe you can do something with CDATA, but I haven't used it like that yet.

    regards

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      I'd use a quick search/replace eg:
      Code:
      sed -e "s/\&/&amp;/g" a.txt > a.txt
      You can't use xsl that effectively with this file since it isn't really xml.

      Comment

      Working...