I have an XML file which has an @url attribute for the element <matimage>. Currently there is a certain image name in the @url attribute, say triangle.png. I want to apply XSLT and modify this URL so that it would be something like assets/images/triangle.png.
I tried the following XSLT:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" />
<!-- Copy everything -->
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="@type[parent::matimage]">
<xsl:attribute name="uri">
<xsl:value-of select="NEW_VALUE"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
As a first step I tried to replace the old value with a new value but that didn't seem to work. Please tell me how to prepend or append a new value to the existing value of the @url attribute.
Here is the sample XML:
<material>
<matimage url="triangle.png">
Some text
</matimage>
</material>
Desired output:
<material>
<matimage url="assets/images/triangle.png">
Some text
</matimage>
</material>