Subject: Re: [xsl] Unexpected result from <a href="...">...</a> in some cases From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 19 Aug 2008 20:50:20 -0400 |
At 2008-08-19 15:05 -0600, Quinn Taylor wrote: Allow me to clarify...
What result to you expect for your test string "/path/to/resource"?
<a href="../../../">[root]</a> / <a href="../../">path</a> / <a href="../">to</a> / resource
What result to you expect for "/to/resource"?
<a href="../../">[root]</a> / <a href="../">to</a> / resource
What result to you expect for "/resource"?
<a href="../">[root]</a> / resource
If you run my code with the commented code un-commented, you can actually see that $parentPath has the value I want, it just isn't printing out what I need.
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"> <!--$path rebuilds the input $text one step at a time--> <xsl:param name="path" select="''"/> <!--$parent builds "../" for each parent in the $text--> <xsl:param name="parent" select="'../'"/> <!--this starts as original and pares down each step--> <xsl:param name="text"/> <!--this is the next branch of the text--> <xsl:variable name="head" select="substring-before($text,'/')"/> <!--this is what is left after the next branch of the text--> <xsl:variable name="tail" select="substring-after($text,'/')"/> <xsl:choose> <xsl:when test="not(contains($tail,'/'))"> <!--at the last portion of the text, put out link--> <a href="{$parent}"> <xsl:choose> <xsl:when test="$parent='../' and $head"> <!--must be at penultimate step--> <xsl:value-of select="$head"/> </xsl:when> <xsl:when test="not(substring-before($path,'/'))"> <!--must be at the very start--> <xsl:text>[root]</xsl:text> </xsl:when> <xsl:otherwise> <!--otherwise must be in the middle--> <xsl:value-of select="substring-before($path,'/')"/> </xsl:otherwise> </xsl:choose> </a> <!--with link done, redo logic ignoring first step in path--> <xsl:text> / </xsl:text> <xsl:choose> <xsl:when test="$path"> <!--next step still has path components, so repeat all this logic as if the first step isn't there--> <xsl:call-template name="printRecursivePath"> <xsl:with-param name="text" select="concat(substring-after($path,'/'),$head,'/',$tail)"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <!--the last step does not have path components--> <b> <xsl:value-of select="$tail"/> </b> <!--some white space to separate results--> <xsl:text>
</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <!--still building the parent string for the current $text--> <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>call xslt quinn.xsl quinn.xsl quinn.html
-- 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 -> |
---|---|---|
Re: [xsl] Unexpected result from <a, Quinn Taylor | Thread | Re: [xsl] Unexpected result from <a, Quinn Taylor |
[xsl] Opera 9.51 doubles <br />, Manfred Staudinger | Date | Re: [xsl] Unexpected result from <a, Quinn Taylor |
Month |