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

Formatting hyperlinks and paragraphs

Subject: Formatting hyperlinks and paragraphs
From: "Peter Simard" <peter@xxxxxxxxxxxxxxx>
Date: Wed, 9 Jul 2003 11:37:43 -0400
xsl hyperlinks
I'm in the middle of developing a simple blogger utility and have a
question:

Among my templates I have 2: one which transforms text to hyperlinks and
another which preserves line breaks.

Ideally I want my result to show a nicely formatted blog entry where
hyperlinks work and line breaks are formatted correctly.

I'm having some difficulty getting this to work.  Both templates work
separately, but not together.

Any input would be appreciated,

Regards,

Pete

My .xslt is as follows:

####################
<xsl:stylesheet version = '1.0'

xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:output method="html" version="4.0" encoding="iso-8859-1" indent="yes"/>

<xsl:template match="/">

<xsl:apply-templates />

</xsl:template>



<xsl:template match="Sample">

<xsl:call-template name="text2hyper" />

<xsl:call-template name="NewLine2Break" />

</xsl:template>

<xsl:template name="text2hyper">

<xsl:param name="text" select="." />

<xsl:choose>

<xsl:when test="contains($text, 'http:')">

<xsl:variable name="textstart" select="substring-before($text,'http:')"
/><!-- everything before token -->

<xsl:variable name="rest" select="concat(substring-after($text,'http:'),'
' )" /><!-- everything after token-->


<xsl:variable name="link" select="concat('http:',substring-before($rest,'
'))" /><!--build the hyper-link-->

<xsl:text>&#160;</xsl:text>

<xsl:variable name="textend" select="substring-after($rest,' ')" />

<xsl:value-of select="$textstart" />

<a>

<xsl:attribute name="href"><xsl:value-of select="$link" /></xsl:attribute>

<xsl:value-of select="$link" />

</a>

<xsl:text>&#160;</xsl:text>

<xsl:call-template name="text2hyper">

<xsl:with-param name="text" select="normalize-space($textend)" />


</xsl:call-template>


</xsl:when>

<xsl:otherwise>

<xsl:value-of select="$text" />

</xsl:otherwise>

</xsl:choose>


<br />

</xsl:template>

<!-- TEMPLATE: converts newline to <br> "break"-->

<xsl:template name="NewLine2Break">

<xsl:param name="string" select="text()"/>

<xsl:param name="from" select="'&#xA;'" />

<xsl:param name="to">

<br /><br />

</xsl:param>

<xsl:choose>

<xsl:when test="contains($string, $from)">

<xsl:value-of select="substring-before($string, $from)" />

<xsl:copy-of select="$to" />

<xsl:call-template name="NewLine2Break">

<xsl:with-param name="string"

select="substring-after($string, $from)" />

<xsl:with-param name="from" select="$from" />

<xsl:with-param name="to" select="$to" />

</xsl:call-template>

</xsl:when>

<xsl:otherwise>

<xsl:value-of select="$string" />

</xsl:otherwise>

</xsl:choose>

</xsl:template>

</xsl:stylesheet>



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


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.