This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Converting an attribute value into an XML fragment


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="&lt;section header=&quot;no&quot;&gt;Testing
> testing&lt;/section&gt;introhunk&lt;br/&gt;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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]