[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Converting attribute value to XML!

Subject: Re: Converting attribute value to XML!
From: "Rui Alberto L." Gonçalves <rui-l-goncalves@xxxxxxxxxxxxx>
Date: 23 Jan 2004 16:48:37 +0000
xsl xml attribute
Thanks Ken, it's working ok now....

Cheers,
Rui

On Fri, 2004-01-23 at 16:19, G. Ken Holman wrote:
> At 2004-01-23 15:28 +0000, Rui Alberto L." Gonçalves wrote:
> >I have a document that looks like:
> >
> ><result>
> >  <filed name="xpto" value="&lt;elem&gt;Hello&lt;elem&gt;"/>
> ></result>
> >
> >and I want to transform to :
> ><result>
> >  <filed name="xpto">Hello</elem>
> ></result>
> 
> That isn't well-formed so it isn't XML ... do you mean
> 
> <result>
>   <filed name="xpto"><elem>Hello</elem></filed>
> </result>
> 
> If so, it is a small change to your stylesheet:
> 
> >I tried:
> >
> ><xsl:template match="*">
> >   <xsl:element name="{name()}">
> >     <xsl:apply-templates select="node()|@*"/>
> >   </xsl:element>
> ></xsl:template>
> >
> ><xsl:template match="filed">
> >  <xsl:element name="filed">
> 
> You are missing the preservation of the name attribute:
> 
>    <xsl:copy-of select="@name"/>
> 
> >    <xsl:value-of select ="@value"/>
> 
> Change the above to:
> 
>    <xsl:value-of disable-output-escaping="yes" select="@value"/>
> 
> >  </xsl:element>
> ></xsl:template>
> >
> >but entities are not resolved. Any idea?
> 
> Resolved?  The entities represent text characters and in your old 
> stylesheet they went out as text characters so they had to be escaped.  By 
> turning off escaping you get what you want, but two caveats:
> 
>   (1) - a processor is not obliged to respect d-o-e=
> 
>   (2) - you can produce a non-well-formed result that isn't XML if you
>         have "bad" data in your text of your input
> 
> If you avoid d-o-e= then your output will *always* be well-formed XML.
> 
> I hope this helps.
> 
> .................... Ken
> 
> t:\ftemp>type rui.xml
> <result>
>   <filed name="xpto" value="&lt;elem&gt;Hello&lt;elem&gt;"/>
> </result>
> 
> t:\ftemp>type rui.xsl
> <?xml version="1.0" encoding="iso-8859-1"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                  version="1.0">
> <xsl:template match="*">
>    <xsl:element name="{name()}">
>      <xsl:apply-templates select="node()|@*"/>
>    </xsl:element>
> </xsl:template>
> 
> <xsl:template match="filed">
>   <xsl:element name="filed">
>     <xsl:copy-of select="@name"/>
>     <xsl:value-of select ="@value" disable-output-escaping="yes"/>
>   </xsl:element>
> </xsl:template>
> 
> </xsl:stylesheet>
> t:\ftemp>saxon rui.xml rui.xsl
> <?xml version="1.0" encoding="utf-8"?><result>
>   <filed name="xpto"><elem>Hello<elem></filed>
> </result>
> t:\ftemp>
> 
> 
> --
> Public courses: sign up for one or both soon to reserve your seat!
> Each week:  Monday-Wednesday: XSLT/XPath;  Thursday-Friday: XSL-FO
> Washington, DC: 2004-03-15           San Francisco, CA: 2004-03-22
> Hong Kong, China: 2004-05-17           Bremen, Germany: 2004-05-24
> World-wide on-site corporate, government & user group XML training
> 
> G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
> Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
> Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
> Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
-- 
Rui Alberto L. Gonçalves <rui-l-goncalves@xxxxxxxxxxxxx>
PT Inovação


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.