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

Re: Making Link in text

Subject: Re: Making Link in text
From: Jonas Mellin <jonas.mellin@xxxxxx>
Date: Fri, 12 Sep 2008 11:33:36 +0200
Re:  Making Link in text
Senthilukvelaan wrote, On 2008-09-12 09:41:
Have a difficulty in producing the expected output.
Any pointer would help.
Input

<P>Please click <LINK>http://www.google.com</LINK>
<LINK_TEXT>
Google
</LINK_TEXT>
on the link below or copy and paste the address
onto your web browser's address window. Once you're on the web page, |
you will be instructed
</P>

xslt

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:template match="P">
<P>
    <xsl:call-template name="markup">
          <xsl:with-param name="content" select="." />
      <xsl:with-param name="link" select="//LINK" />
      <xsl:with-param name="text" select="//LINK_TEXT" />
    </xsl:call-template>
  </P>
</xsl:template>
</body>
</html>
</xsl:template>

<xsl:template match="P" name="markup"  >
  <xsl:param name="link" />
    <xsl:param name="text" />
  <a href="{$link}">
  <xsl:value-of select="$text" />
   </a>
</xsl:template>

</xsl:stylesheet>

The following does the transformation:


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>


<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="LINK">
<a><xsl:attribute name="href"><xsl:value-of select="."/></xsl:attribute>
<xsl:apply-templates select="following::LINK_TEXT[1]" mode="inLink"/>
</a>
</xsl:template>

<xsl:template match="LINK_TEXT" mode="inLink">
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="LINK_TEXT">
</xsl:template>

</xsl:stylesheet>

You seem to have a vague idea of how the XSLT processor works. Further, it is better to make the LINK and LINK_TEXT subelements of a common element such as LINKINFO element. For example, replace

<LINK>http://www.google.com</LINK>
<LINK_TEXT>
Google
</LINK_TEXT>

with

<LINKINFO>
<LINK>http://www.google.com</LINK>
<LINK_TEXT>
Google
</LINK_TEXT>
</LINKINFO>

Then, we can replace the ugly and not so robust templates for LINK and LINK_TEXT (template 3, 4 and 5) with

<xsl:template match="LINKINFO">
<a><xsl:attribute name="href"><xsl:value-of select="LINK"/></xsl:attribute>
<xsl:value-of select="LINK_TEXT"/>
</a>
</xsl:template>

Note that I would choose different names for LINKINFO and LINK. For example, LINKINFO => LINK and LINK => REF

/Jonas




Desired output.


<html>
<body>
<P>Please click
<a href="http://www.google.com">
Google
</a>
on the link below or copy and paste the address
onto your web browser's address window. Once you're on the web page, |
you will be instructed
</P>
</body>
</html>

Thanks,
S



--
Carpe Diem!
===
Jonas Mellin, Assistant Professor in Computer Science
School of Humanities and Informatics, Building E-2
University of Skvvde, P.O. Box 408, SE-541 28 Skvvde, Sweden
Phone: +46 500 448321, Fax: +46 500 448399
Email: jonas.mellin@xxxxxx, URL: http://www.his.se/melj

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.