Skip to content

Commit

Permalink
Only make the image url absolute if it isn't already
Browse files Browse the repository at this point in the history
  • Loading branch information
egli committed May 15, 2024
1 parent 8376cb3 commit 994f1a0
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions resources/xslt/absolutizeImagePath.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,23 @@
doctype-system="http://www.daisy.org/z3986/2005/dtbook-2005-3.dtd" />

<xsl:template match="dtb:img/@src">
<xsl:attribute name="src">
<xsl:value-of select="concat($absolute-image-path, '/', .)"/>
</xsl:attribute>
<xsl:attribute name="src">
<xsl:choose>
<!-- Only make the url absolute if it isn't already -->
<xsl:when test="matches(., '^([a-z+]+:)?//', 'i')">
<!-- we are looking at an absolute url, no need to make it absolute -->
<xsl:value-of select="."/>
</xsl:when>
<xsl:when test="starts-with(.,'/')">
<!-- we are looking at a relative url starting with '/' -->
<xsl:value-of select="concat($absolute-image-path, .)"/>
</xsl:when>
<xsl:otherwise>
<!-- we are looking at a relative url -->
<xsl:value-of select="concat($absolute-image-path, '/', .)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>

<!-- Copy all other elements and attributes -->
Expand Down

0 comments on commit 994f1a0

Please sign in to comment.