xsl-list
[Top] [All Lists]

Re: [xsl] Unexpected result from <a href="...">...</a> in some cases

2008-08-19 15:42:15
At 2008-08-19 14:19 -0600, Quinn Taylor wrote:
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.

Sorry ... I do not understand what you want.

What result to you expect for your test string "/path/to/resource"?

What result to you expect for "/to/resource"?

What result to you expect for "/resource"?

What result to you expect for "resource"?

The problem occurs for path components between the first and the last
component.

Because you are not passing your intermediate results to the recursively called template.

(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.)

Then I am really unclear as to what result you want for the given path.

Below is an example that translates:

  "/path/to/resource" to "../../resource"
  "/to/resource" to "../resource"
  "/resource" to "resource"

But I'm only guessing what you want from your succinct description. If you give some examples then someone on the list can probably guide you to the right result.

For now, though, look at what I'm doing below when I pass the intermediate results to the called template ... that may be the bit you are missing. When I write recursive templates I always need to keep track of what is being built along the way, or the intermediate work gets lost. This appears to be the evidence you are presenting, so I'm guessing that is your issue.

Note that even what I have below is incomplete since I don't know what you want to do with "resource" as your input path.

I hope this helps.

. . . . . . . . . . . . Ken



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>

t:\ftemp>


--
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(_at_)CraneSoftwrights(_dot_)com
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


--~------------------------------------------------------------------
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>
--~--