[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Converting embedded URLs int hot links via XSL

Subject: RE: Converting embedded URLs int hot links via XSL
From: bryan.s.schnabel@xxxxxxxxxxxxxx
Date: Fri, 16 Apr 2004 15:17:41 -0700
links in xsl
Here's an approach you could use.  The "choose's" and "substring-before's"
and "substring-after's" get kind of shaggy.  And choice of substring
conditions make some pretty lazy assumptions about the expected form of the
url's, but you get the idea:

<xsl:template match="node()|@*">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()"/>
 </xsl:copy>
</xsl:template>

<xsl:template match="text()" priority="2">
 <xsl:choose>
  <xsl:when test="contains(.,'http')">
   <xsl:variable name="after.com" select="substring-after(.,'.com')" />
   <xsl:value-of select="substring-before(.,'http')" />
    <a>
     <xsl:attribute name="href">
      <xsl:value-of
select="concat('http',substring-after(substring-before(.,'.com'),'http'),'.c
om')" />
     </xsl:attribute>
     <xsl:value-of
select="concat('http',substring-after(substring-before(.,'.com'),'http'),'.c
om')" />
    </a> 
    <xsl:call-template name="lazy-recurs">
     <xsl:with-param name="after-.com">
      <xsl:value-of select="$after.com" />
     </xsl:with-param>
    </xsl:call-template>
  </xsl:when>
  <xsl:otherwise>
   <xsl:value-of select="." />
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<xsl:template name="lazy-recurs">
 <xsl:param name="after-.com" />
  <xsl:choose>
   <xsl:when test="contains($after-.com,'http')">
    <xsl:variable name="after.com"
select="substring-after($after-.com,'.com')" />
      <xsl:value-of select="substring-before($after-.com,'http')" />
       <a>
        <xsl:attribute name="href">
         <xsl:value-of
select="concat('http',substring-after(substring-before($after-.com,'.com'),'
http'),'.com')" />
        </xsl:attribute>
        <xsl:value-of
select="concat('http',substring-after(substring-before($after-.com,'.com'),'
http'),'.com')" />
       </a>
     <xsl:call-template name="lazy-recurs">
      <xsl:with-param name="after-.com">
       <xsl:value-of select="$after.com" />
      </xsl:with-param>
     </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="$after-.com" />
   </xsl:otherwise>
  </xsl:choose>
</xsl:template>

-----Original Message-----
From: Ghulam Abbas [mailto:abbasg_99@xxxxxxxxx] 
Sent: Friday, April 16, 2004 12:53 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Converting embedded URLs int hot links via XSL


Here is the sample xml

<strings>
<str>Test url string: 'http://www.yahoo.com' and one
more url "https://www.yahoo.com"</str>
</strings>

So, is there a way to extract the urls above from str
and then convert them into hotlinks. The desired html
is something like
Test url string: <a href="http://www.yahoo.com"
target="_blank">'http://www.yahoo.com'</a> and one
more url <a href="https://www.yahoo.com"
target="_blank">"https://www.yahoo.com"</a>

I've tried recursion but it doesn't work. Any ideas???

Thanks,
Abbas


	
		
__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.