Re: [xsl] Evaluating XML inside attributes (using XSLT 2.0 and Saxon)

Subject: Re: [xsl] Evaluating XML inside attributes (using XSLT 2.0 and Saxon)
From: Michael Ludwig <milu71@xxxxxx>
Date: Wed, 24 Mar 2010 23:46:56 +0100
Jacobus Reyneke schrieb am 24.03.2010 um 20:39:27 (+0200):

> I can't get past the fact that sometimes I end up with attributes that
> will get part of their content from other parts of the XML document.

Fine.

> Can anyone please share some ideas around evaluating information for
> use inside xml attributes. I know it's ugly, horrible and terrible to
> escape XML an dump it inside an attribute

Should be avoided under all circumstances. No excuse :-)

> but I need to reference content by id from inside attributes from time
> to time.

Why don't you just use entities and entity references? Good old DTD does
the job for you:

$ cat five.xml
<!DOCTYPE root [
<!ENTITY johny "Johny">
]>
<root>
  <information lookup-id="5">
    &johny;             
  </information>
  <chapter title="The life of &johny;">
     Everyone knew that &johny; was a happy child  
  </chapter>
</root>

$ xmllint --noent five.xml
<?xml version="1.0"?>
<!DOCTYPE root [
<!ENTITY johny "Johny">
]>
<root>
  <information lookup-id="5">
    Johny             
  </information>
  <chapter title="The life of Johny">
     Everyone knew that Johny was a happy child  
  </chapter>
</root>

That way, you won't need information/@lookup-id.

If you insist on using cryptic numbers, you could pre-generate the
entities and store them in a file called five.ent which you then
reference from the DOCTYPE.

-- 
Michael Ludwig

Current Thread