I am using unparsed-entity-uri() to resolve graphic entities, but only want the filename without the full path, as the graphics on the target server are in a different path.
I'm able to get the desired result, but have a nagging suspicion that there has to be an easier way to do this, maybe without recursion. Any suggestions?
Source is something like this:
Code:
<?xml version="1.0"?>
<!DOCTYPE cmm [
<!ENTITY graphic1 SYSTEM "c:\graphics\some_folder\abcd.tif" NDATA ccitt4>
]>
<cmm>
<sheet gnbr="graphic1"/>
</cmm>
XSL is something like this:
Code:
<xsl:template match="/">
<body><xsl:apply-templates/></body>
</xsl:template>
<xsl:template match="sheet">
<xsl:variable name="imgref" select="unparsed-entity-uri(@gnbr)"/>
<xsl:element name="img">
<xsl:attribute name="href">
<xsl:call-template name="getFilename">
<xsl:with-param name="uri" select="translate($imgref,'\','/')"/>
</xsl:call-template>
</xsl:attribute>
</xsl:element>
</xsl:template>
<xsl:template name="getFilename">
<xsl:param name="uri"/>
<xsl:choose>
<xsl:when test="contains($uri,'/')">
<xsl:call-template name="getFilename">
<xsl:with-param name="uri" select="substring-after($uri,'/')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$uri"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Result is:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<body>
<img href="abcd.tif"/>
</body>