I have an input XML document something like this:
<text>
<p>
Download the software from <link id="blah">
</p>
</text>
<links>
<link id="blah">
<url>http://blah</url>
</link>
</links>
And I would like my output document to be:
<text>
<p>
Download the software from <a href="http://blah"> http://blah </a>
</p>
</text>
That is: I want to copy the existing input document nodes as-is but also replace certain nodes (for instance <link>) with an expanded version: based on other information contained in the input document.
I tried to use <xsl:copy .../> to first copy in the fragment like this:
<xsl:variable name="frag">
<xsl:copy-of select="text"/>
</xsl:variable>
But when I then output the variable like this:
<xsl:value-of select="$frag">
The output doesn’t appear to keep the paragraph tags ? So I’m not sure the xsl-copy has copied the nodes, or just the text somehow ?
If I place in just the following (strip out the <xsl:variable/> ‘wrapper’), it DOES preserve the tags in the output doc ?
<xsl:copy-of select="text"/>
But of course, I need to first re-map that ‘link’ tag to an anchor tag….
I haven’t even started to work out how to then replace the contents of the variable (in a new variable of course) with the link information….
Try this :
With the following input :
You get :