Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XSLT string replacement question

From: richard@------.--.--.-- (------- -----)
To: 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

>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
>&lt;java version="1.4.2_03" class="java.beans.XMLDecoder"&gt;
> &lt;object class="javax.swing.JButton"&gt;
>  &lt;string&gt;Hello, world&lt;/string&gt;
> &lt;/object&gt;
>&lt;/java&gt;

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;amp; and &amp;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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent