[xsl] Building cross-referenced texts with XSLT

Subject: [xsl] Building cross-referenced texts with XSLT
From: Aaron Optimizer Digulla <digulla@xxxxxxxx>
Date: Sun, 25 Aug 2002 20:56:58 +0200

I've got a large database (roughly 1MB) which contains comics,
stories and characters by Stan Sakai. Here is an example:

        <character id="atsuko">
            <first-story ref="frost-and-fire"/>
            <first-issue ref="uy-vol1-nr19"/>
            <death ref="frost-and-fire"/>
            <img url="$TOP/uywho/atsuko.gif"
            <note>"<em>Atsuko</em>" means Hot Child</note>

<p>A peasant girl who possessed swords belonging to a Samurai named &Nagao;.
&Nagao; and Atsuko were in love and had planned to commit lovers suicide
before &Nagao; was killed by Atsuko's brother for money.</p>

<p>Unaware of this, Atsuko kept the swords as a memento of her lost love.
&Usagi;, hired by &Nagao;'s widow - Lady <char-link ref="lady-koriko"/>, to
retrieve the swords, offered to pay for the return of the swords. Atsuko
refused and &Usagi; left. Atsuko and her brother argued about the swords,
her brother trying to take them by force, accidentally killing her.</p>


As you can see, the text contains lots of entities which are defined
like this:

<!ENTITY Nagao '<char-link ref="nagao">Nagao</char-link>'>
<!ENTITY LadyAsano '<char-link ref="asano">Lady Asano</char-link>'>

How can I write a script that converts "Lady Asano" into &LadyAsano;
and "Nagao" into &Nagao; but which leaves &Nagao; (or the expanded
entity) alone?

Note that preserving the entities is not a problem; I can easily
convert the expanded form back into the entity notation should I
have to. But how do I transform char content in specific elements
while not doing it in other elements?

How do I make sure that "Lady Asano" is transformed into &LadyAsano;
while "Asano" is transformed into &Asano; while
"<char-link ref="asano">Lady Asano</char-link>" should be left alone?
Note that I have about 2-300 entities to check.

Also, I would like to suppress the expansion of "Atsuko" inside
of her description.

And the original layout (whitespace) should be preserved (ie.
I don't want "hired by &Nagao;" become "hired by&Nagao;").

Any ideas?

Sowatec AG,       CH-8330 Pfäffikon (ZH)
Witzbergstr. 7,   http://www.sowatec.com
Tel: +41-(0)1-952 55 55
Fax: +41-(0)1-952 55 66
Aaron "Optimizer" Digulla, digulla@xxxxxxxxxxx

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

Current Thread