This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Identifing link (advanced)



Sorry, have to change the <A> tag to work as you want :)

 <xsl:template match="text">
  <xsl:call-template name="add-link">
   <xsl:with-param name="string" select="."/>
  </xsl:call-template>
  <br/><br/>
 </xsl:template>

 <xsl:template name="add-link">
  <xsl:param name="string"/>
  <xsl:param name="link">
   <xsl:choose>
    <xsl:when test="contains($string, 'http://')">http://</xsl:when>
    <xsl:when test="contains($string, 'file://')">file:/</xsl:when>   <!--
Doesn't need the file:/// because this one do both -->
    <xsl:when test="contains($string, 'ftp://')">ftp://</xsl:when>    <!--
yes, it recognise ftp:// also, any other just join  another when clause -->
    <xsl:otherwise>
     <xsl:value-of select="false()"/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:param>
  <xsl:choose>
   <xsl:when test="contains($string, $link)">
    <xsl:value-of select="substring-before($string, $link)"/>
    <a href="{$link}{substring-before(substring-after($string, $link), '
')}">    <!---- here I had to substitut 'http://' for {$link} -->
    <xsl:value-of select="$link"/>    <!-- this puts the correct string in
the output -->
    <xsl:value-of select="substring-before(substring-after($string, $link),
' ')"/>
    </a>
    <xsl:text> </xsl:text>
    <xsl:call-template name="add-link">
     <xsl:with-param name="string"
select="substring-after(substring-after($string, $link), ' ')"/>
    </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="$string"/>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>



-----Original Message-----
From: owner-xsl-list@lists.mulberrytech.com
[mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Raimund
Kammering
Sent: Friday, June 07, 2002 6:01 PM
To: XSL-List
Subject: [xsl] Identifing link (advanced)


Hi,

first of all I would like to thank Charles (you are completly right -
but since I needed some XSLT solution I was satisfied with Joerg's
solution), Joerg (great since I exactly needed this recursion) and
Andrew (that is amazing compact from)!
My own guess was nearly the same as Joerg posted - BUT I missed the idea
of the recursive call.

So anyway this worked pretty well and I was going to do some minor
modifications (at least I thought so) and run into
some big trouble (again).
What I wanted to do is to also identify the 'file:/' and 'file:///'
URL's. This sounds like an easy choose ... clause - but when
I went into the detail I got again stuck.
The problem is that a simple contains($string, 'file:/') will match even
if there are some 'http:/' strings and now one has to take care of the
ordering of these strings. The situation is getting more complicated (at
least for my) by the fact, that the choose is exiting after the first
match. So the simplest model like:

    <xsl:param name="link">
      <xsl:choose>
        <xsl:when test="contains($string, 'http://')">
          <xsl:value-of select="'http://'"/>
        </xsl:when>
        <xsl:when test="contains($string, 'file:/')">
          <xsl:value-of select="'file:/'"/>
        </xsl:when>
        <xsl:when test="contains($string, 'file:///')">
          <xsl:value-of select="'file:///'"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="false()"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:param>

will in case that all three strings are present always give
link='http://' (if the choose is build this way).
So in principle it is clear for me what has to be done (at least
nearly). But I am having a hard time to get this really implemented
(building kind of hash list or ...).
Here is the code snipplet I got set up till now (that is not finding all
strings):

  <xsl:template name="add-link">
    <xsl:param name="string"/>
    <xsl:param name="link">
      <xsl:choose>
        <xsl:when test="contains($string, 'http://')">
          <xsl:value-of select="'http://'"/>
        </xsl:when>
        <xsl:when test="contains($string, 'file:/')">
          <xsl:value-of select="'file:/'"/>
          <xsl:value-of select="position()"/>
        </xsl:when>
        <xsl:when test="contains($string, 'file:///')">
          <xsl:value-of select="'file:///'"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="false()"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:param>
    <xsl:choose>
      <xsl:when test="$link!='false'">
        <xsl:value-of select="substring-before($string, $link)"/>
        <a href="{$link}{substring-before(substring-after($string,
$link), ' ')}">
          <xsl:value-of select="concat($link,
substring-before(substring-after($string, $link), ' '))"/>
        </a>
        <xsl:text> </xsl:text>
        <xsl:call-template name="add-link">
          <xsl:with-param name="string"
select="substring-after(substring-after($string, $link), ' ')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$string"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

So if anybody has an idea how to implement this search/ordering in a
easy (or at least simple) way I would be happy!

Raimund

--
DESY -MVP-
Notkestrasse 85
D-22603 Hamburg
Tel.: +49 40 8998 -4903
e-mail: Raimund.Kammering@desy.de

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]