ham on wry
ham on wry

Reputation: 71

XSLT - Convert URI backslashes to forward slash

We are converting legacy HTML files to DITA. I would like to convert windows paths with backslashes in the href attribute

<a href="c:\developer\file.html">

to forward slashes

<xref href="c:/developer/file.dita">

I have attempted to use both replace and translate (XSLT is v2) with no success. I have also tried the string.replace method on http://geekswithblogs.net/Erik/archive/2008/04/01/120915.aspx with the same result.

Upvotes: 1

Views: 3193

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117043

I have attempted to use both replace and translate (XSLT is v2) with no success.

translate(@href, '\', '/')

should work just fine. Or, if you prefer to do it all in one, try:

<xsl:template match="a">
    <xref href="{replace(replace(@href, '\\', '/'), '.html', '.dita') }">
        <xsl:apply-templates/>
    </xref>
</xsl:template>

Upvotes: 11

Related Questions