Remove part of image src path

I have lot of html tags in my xml (well formated) which i need to transform to html using xsl. I am using xsl-copy-of function to copy and display it as is.Everything is working fine, but now i got a problem. I want to remove a string “/” from all image src tags.

ie. <img src=“/” />

This should become

<img src=“/Global/Images/test.jpg” />

for all img src tags / should be replaced.

I googled and read like using xsl-copy-of we cannot do the replacement. I need to use identity template or so.I dont have much idea, i am not an xsl expert, so can anyone solve the problem for me?


<?xml version=“1.0” encoding=“UTF-8”?>
<?xml-stylesheet type=“text/xsl” href=“test.xsl”?>
<br />
<img src=“/” />

I want to copy all HTML contents only under root/content and transform it through XSL to produce HTML code.


<?xml version=“1.0” ?>
<xsl:stylesheet version=“1.0” xmlns:xsl=“”>
<xsl:output method=“html” indent=“yes” />
<xsl:template match=“/”>
<xsl:copy-of select=“root/content”/>

Replaced? Or do you mean “removed”? If removed, this should work:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
    <xsl:output method="html" indent="yes" />
    <xsl:template match="/">
            <xsl:apply-templates select="root/content"/>

    <xsl:template match="node()">

    <xsl:template match="img">
        <img src="{substring-after(@src, '/')}" />

Note that this also assumes ALL of your img tags’ src attributes start with “/” or don’t contain it at all. If there’s a danger that some of your images don’t start with this, but contain it, the procedure will be slightly more complicated.

If you really meant “repalced”, you can place the new value right before “{”, or within it, like so:

{concat('', substring-after(@src, '/')}

(assuming “” is the new value you want)