If I were to have the following XML document…
<?xml version="1.0"?>
<document>
<title>Foobar</title>
<article>
Phasellus ultrices arcu suscipit velit laoreet eu dignissim
dolor pulvinar. Proin ac libero a diam laoreet iaculis nec eu risus.
<ref url="http://en.wikipedia.org/wiki/FooBar">Foobar</ref> potenti.
Duis placerat laoreet est nec fringilla. Quisque vitae semper erat.
</article>
</document>
…how would I translate the article element to the following?
<p>
Phasellus ultrices arcu suscipit velit laoreet eu dignissim
dolor pulvinar. Proin ac libero a diam laoreet iaculis nec eu risus.
<a href="http://en.wikipedia.org/wiki/FooBar">Foobar</a> potenti.
Duis placerat laoreet est nec fringilla. Quisque vitae semper erat.
</p>
Specifically, it’s the ref to a translation I’m interested in, since it’s embedded within a block of plain text.
If you build upon the standard XSTL Identity Transform, this is a straight-forward task, you just need a template to match a ref element and output an a element instead.
And to replace the attribute, you then have another template
Note that if your ref element was guaranteed to always have an url attribute, you could also simplify those two templates into just one, like this:
You would then add other templates to replace any other elements as required, such as article being changed to p, and also a template to not output the title element.
Here is the full XSLT
When applied to your sample XML, the following is output