Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - XSLT string replacement question >Thread Next - Re: XSLT string replacement question Re: XSLT string replacement questionTo: NULL Date: 6/2/2004 12:29:00 AM In article <af913759.0406011546.1feda850@p...>, J Trost <jt6211@e...> wrote: >I need to be able to convert XML like this: > ><?xml version="1.0" encoding="UTF-8"?> ><java version="1.4.2_03" class="java.beans.XMLDecoder"> > <object class="javax.swing.JButton"> > <string>Hello, world</string> > </object> ></java> >Into XML like this ><?xml version="1.0" encoding="UTF-8"?> ><java version="1.4.2_03" class="java.beans.XMLDecoder"> > <object class="javax.swing.JButton"> > <string>Hello, world</string> > </object> ></java> You can't do the XML declaration, because XSLT doesn't see it. You can do the rest, but it will be tedious. You need a template that matches any element. It should then output "<" as text, followed by the local-name() of the element, and a space. Then apply-templates to the attributes. Output ">", then apply-templates to the children. Handle the end-tag in the same way. The template for the attributes will be even more tedious, because you will need to handle the possibility of quotes in the attribute value. Similarly, the template for text will have to handle & and < specially (you will need to output &amp; and &lt;). If your XML may use namespaces, you will need to look at the namespace nodes to determine appropriate prefixes for the element and attribute names, and you will have to output namespace declarations. You really don't want to do this. Use sed instead. -- Richard | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
