Let’s say I have an XML node like the following:
<item id="20">
<name>Baz</name>
<description>
If you liked this, you should check out <related id="5">Foo</related>
and <related id="7">Bar</related>!
</description>
<item>
When outputting the description via XSLT, I want the text() to be rendered such that each of the <related> nodes become anchor tags. How would I go about doing this?
Edit: Desired output added per Kirill’s request. I’d like it to look something like this:
If you liked this, you should check out <a href=”/items/5″>Foo<a> and <a href=”/items/7″>Bar<a>!
Create a template that overrides the default handling for
relatedelements:Output:
This is a fundamental XSLT pattern. The first template implements the Identity Transform, which copies most nodes through unchanged. The second template overrides the first in the case of
relatedelements, converting them to HTML anchors.