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 “/mydomain.com” from all image src tags.

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

This should become

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

for all img src tags /mydomain.com 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?

My XML


<?xml version=“1.0” encoding=“UTF-8”?>
<?xml-stylesheet type=“text/xsl” href=“test.xsl”?>
<root>
<content>
<h1>Hai</h1>
<br />
<img src=“/mydomain.com/Global/Images/test.jpg” />
</content>
</root>

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

test.xsl


<?xml version=“1.0” ?>
<xsl:stylesheet version=“1.0” xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”>
<xsl:output method=“html” indent=“yes” />
<xsl:template match=“/”>
<div>
<xsl:copy-of select=“root/content”/>
</div>
</xsl:template>
</xsl:stylesheet>

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

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes" />
    <xsl:template match="/">
        <div>
            <xsl:apply-templates select="root/content"/>
        </div>
    </xsl:template>

    <xsl:template match="node()">
        <xsl:copy>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

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

Note that this also assumes ALL of your img tags’ src attributes start with “/mydomain.com” 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('http://mydomain.com', substring-after(@src, '/mydomain.com')}

(assuming “http://mydomain.com” is the new value you want)