Hi All-
I have the following XML which basically sets the groundwork for us to
build a simple relative href from where the XML object resides
(source_xml_path) to where the linked object resides in a directory
structure (source_document_path):
<?xml version="1.0" encoding="UTF-8"?>
<root>
<source_xml_path>/web_cabinet/folder1/folder2/folder3</source_xml_path>
<source_document_path>/web_cabinet/folder1/folder2/linkingToDocument.doc</source_document_path>
</root>
However, the only instance (that I have found so far) where this fails is
in the above XML. Any other path specifications work fine and construct
the relative path. Right now, I am just getting a stack overflow which I
am trying to nail down now. Any suggestions on a resolution is greatly
appreciated.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="from" select="/root/source_xml_path"/>
<xsl:variable name="to" select="/root/source_document_path"/>
<xsl:template match="/root">
<html>
<head>
<title>Getting relative paths</title>
</head>
<body>
<xsl:value-of select="$from"/>
<br/>
<xsl:value-of select="$to"/>
<br/>
<xsl:call-template name="relativeUrl">
<xsl:with-param name="from" select="$from"/>
<xsl:with-param name="to" select="$to"/>
</xsl:call-template>
</body>
</html>
</xsl:template>
<!--****************************************************************************-->
<!--RELATIVE URL-->
<!--****************************************************************************-->
<xsl:template name="relativeUrl">
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:variable name="samePath">
<xsl:choose>
<!--<xsl:when test="starts-with($to,$from)">-->
<xsl:when test="$to=$from">
<xsl:choose>
<xsl:when
test="contains(substring-after(substring-after($to,$from),'/'),'/')">
<xsl:value-of select="false()"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="true()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="false()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$samePath='false'">
<xsl:variable name="strFrom">
<xsl:call-template name="str">
<xsl:with-param name="from" select="$from"/>
<xsl:with-param name="to" select="$to"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="dotdotSlash">
<xsl:call-template name="dotSlash">
<xsl:with-param name="convert" select="$strFrom"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="url">
<xsl:value-of select="$dotdotSlash"/>
<xsl:value-of
select="substring-after(substring-after($to,substring-before($from,$strFrom)),'/')"/>
</xsl:variable>
<xsl:value-of select="$url"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="substring-after(substring-after($to,$from),'/')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="str">
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:choose>
<xsl:when
test="contains(substring-before(substring-after($from,'/'),'/'),substring-before(substring-after($to,'/'),'/'))
and
contains(substring-before(substring-after($to,'/'),'/'),substring-before(substring-after($from,'/'),'/'))">
<xsl:call-template name="str">
<xsl:with-param name="from" select="substring-after($from,'/')"/>
<xsl:with-param name="to" select="substring-after($to,'/')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$from"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="dotSlash">
<xsl:param name="convert"/>
<xsl:param name="result"/>
<xsl:choose>
<xsl:when test="substring-after($convert,'/')!=''">
<xsl:variable name="newResult">
<xsl:value-of select="$result"/>../</xsl:variable>
<xsl:call-template name="dotSlash">
<xsl:with-param name="convert"
select="substring-after($convert,'/')"/>
<xsl:with-param name="result" select="$newResult"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$result"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Thank you all so much.
CA
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--