Subject: Re: [xsl] Unexpected result from <a href="...">...</a> in some cases From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 19 Aug 2008 16:41:27 -0400 |
I've created a recursive template (printRecursivePath) to process a directory path and build up a string of links from the right side so as to correctly increase the number of "../" elements for parent link.
The problem occurs for path components between the first and the last component.
(I'm a CS grad student, so recursion has become second nature to me and I'm quite certain the error isn't there. I've debugged this is oXygen, and all the variables had the expected values.)
"/path/to/resource" to "../../resource" "/to/resource" to "../resource" "/resource" to "resource"
t:\ftemp>type quinn.xsl <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes"/>
<xsl:template match="*"> <xsl:call-template name="printRecursivePath"> <xsl:with-param name="text">/path/to/resource</xsl:with-param> </xsl:call-template> <xsl:call-template name="printRecursivePath"> <xsl:with-param name="text">/to/resource</xsl:with-param> </xsl:call-template> <xsl:call-template name="printRecursivePath"> <xsl:with-param name="text">/resource</xsl:with-param> </xsl:call-template> </xsl:template>
<!-- Split path components at '/', add parent directory links --> <xsl:template name="printRecursivePath"> <xsl:param name="path" select="''"/> <xsl:param name="parent" select="''"/> <xsl:param name="text"/> <xsl:variable name="head" select="substring-before($text,'/')"/> <xsl:variable name="tail" select="substring-after($text,'/')"/> <xsl:choose> <xsl:when test="not(contains($tail,'/'))"> <!--at the last portion of the file name--> <a href="{$parent}{$tail}"> <xsl:value-of select="concat($path,$head,'/',$tail)"/> </a> <xsl:text> </xsl:text> </xsl:when> <xsl:otherwise> <xsl:call-template name="printRecursivePath"> <xsl:with-param name="parent" select="concat($parent,'../')"/> <xsl:with-param name="path" select="concat($path,$head,'/')"/> <xsl:with-param name="text" select="$tail"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template>
</xsl:stylesheet> t:\ftemp>xslt quinn.xsl quinn.xsl con <a href="../../resource">/path/to/resource</a> <a href="../resource">/to/resource</a> <a href="resource">/resource</a>
-- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Unexpected result from <a hre, Quinn Taylor | Thread | Re: [xsl] Unexpected result from <a, Quinn Taylor |
[xsl] replaceing a href in RSS link, Co | Date | Re: [xsl] Unexpected result from <a, Quinn Taylor |
Month |