I have the following piece of code in my XSLT file:
<xsl:copy-of select="/root/Algemeen/foto/node()" />
In the XML file the node /root/Algemeen/foto/
holds an HTML image, for example: <img src="somephoto.jpg" />
What I would like to do is to add a fixed width to the image. But the following doesn't work:
<xsl:copy-of select="/root/Algemeen/foto/node()">
<xsl:attribute name="width">100</xsl:attribute>
</xsl:copy-of>
xsl:copy-of
performs a deep copy of the selected node, but doesn't provide an opportunity to alter it.You will want to use
xsl:copy
and then add additional nodes inside.xsl:copy
just copies the node and namespace attributes, but not the regular attributes and child nodes, so you will want to ensure that youapply-templates
to push the other nodes through as well.xsl:copy
does not have a@select
, it works on the current node, so wherever you were applying the<xsl:copy-of select="/root/Algemeen/foto/node()" />
, you will need to change to<xsl:apply-templates select="/root/Algemeen/foto/node()" />
and move theimg
logic into a template.Something like this: