This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Converting an attribute value into an XML fragment
- To: "Joel P Thornton" <joelt at tlchoices dot com>
- Subject: Re: [xsl] Converting an attribute value into an XML fragment
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Mon, 9 Apr 2001 23:42:58 +0100
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <NDBBJLODDMKIOFAANFMHKEOBCLAA.joelt@tlchoices.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Joel,
> I am trying to convert the value of an attribute into an XML fragment in
> XSL. Here is what my XML looks like:
>
> <row
> title="XMLContent"
> value="<section header="no">Testing
> testing</section>introhunk<br/>blah"
> />
>
> So, when converted into an XML fragment, row/@value should look like this:
>
> <section header="no">Testing testing</section>introhunk<br/>blah
As far as the processor is concerned, the value of the 'value'
attribute is just a string. It can't recognise the fact that this
string is supposed to be serialised XML.
So given this XML source, the only sensible option is to use
disable-output-escaping to make the processor forget about the fact
that it's supposed to be outputting XML, and just make it output
precisely the string that you want - a less than sign followed by the
string 'section' and so on.
You can do this with:
<xsl:value-of disable-output-escaping="yes" select="row/@value" />
(Note - the insensible option is to write an XML parser in XSLT ;)
Disabling output escaping like this is problematic firstly because you
have to be careful that you are actually producing well-formed XML
when you use it, and secondly because processors are not guaranteed to
support it.
You would be a lot better off if the value of the row was stored
actually as XML within the row element:
<row title="XMLContent">
<section header="no">Testing testing</section>introhunk<br />blah
</row>
Then you could simply do:
<xsl:copy-of select="row/node()" />
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list