<xsl:template name="add-xml-base">
<!-- * Get a title for current doc so that we let the user -->
<!-- * know what document we are processing at this point. -->
<xsl:variable name="doc.title">
<xsl:call-template name="get.doc.title"/>
</xsl:variable>
<xsl:if test="not(@xml:base)">
<xsl:variable name="base">
<xsl:choose>
<xsl:when test="function-available('saxon:systemId')">
<xsl:value-of select="saxon:systemId()"/>
</xsl:when>
<xsl:when test="function-available('NodeInfo:systemId')">
<xsl:value-of select="NodeInfo:systemId()"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="log.message">
<xsl:with-param name="level">Warn</xsl:with-param>
<xsl:with-param name="source" select="$doc.title"/>
<xsl:with-param name="context-desc">
<xsl:text>no @xml:base</xsl:text>
</xsl:with-param>
<xsl:with-param name="message">
<xsl:text>cannot add @xml:base to node-set root element</xsl:text>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="log.message">
<xsl:with-param name="level">Warn</xsl:with-param>
<xsl:with-param name="source" select="$doc.title"/>
<xsl:with-param name="context-desc">
<xsl:text>no @xml:base</xsl:text>
</xsl:with-param>
<xsl:with-param name="message">
<xsl:text>relative paths may not work</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- debug
<xsl:message>base is <xsl:value-of select="$base"/></xsl:message>
-->
<xsl:if test="$base != ''">
<xsl:attribute name="xml:base">
<xsl:call-template name="systemIdToBaseURI">
<xsl:with-param name="systemId">
<!-- file: seems to confuse some processors. -->
<xsl:choose>
<!-- however, windows paths must use file:///c:/path -->
<xsl:when test="starts-with($base, 'file:///') and substring($base, 10, 1) = ':'">
<xsl:value-of select="$base"/>
</xsl:when>
<xsl:when test="starts-with($base, 'file:/') and substring($base, 8, 1) = ':'">
<xsl:value-of select="concat('file:///', substring-after($base,'file:/'))"/>
</xsl:when>
<xsl:when test="starts-with($base, 'file:///')">
<xsl:value-of select="substring-after($base,'file://')"/>
</xsl:when>
<xsl:when test="starts-with($base, 'file://')">
<xsl:value-of select="substring-after($base,'file:/')"/>
</xsl:when>
<xsl:when test="starts-with($base, 'file:/')">
<xsl:value-of select="substring-after($base,'file:')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$base"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
</xsl:if>
</xsl:if>
</xsl:template> |