Thanks you very much for the idea.
I have not used the "mode". Mode is really handy in this case.
Thanks,
Senthil
On Fri, Sep 12, 2008 at 2:33 AM, Jonas Mellin
<jonas(_dot_)mellin(_at_)his(_dot_)se> wrote:
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
--~------------------------------------------------------------------
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>
--~--
--
Carpe Diem!
===
Jonas Mellin, Assistant Professor in Computer Science
School of Humanities and Informatics, Building E-2
University of Skövde, P.O. Box 408, SE-541 28 Skövde, Sweden
Phone: +46 500 448321, Fax: +46 500 448399
Email: jonas(_dot_)mellin(_at_)his(_dot_)se, URL: http://www.his.se/melj
--~------------------------------------------------------------------
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>
--~--
--~------------------------------------------------------------------
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>
--~--