xsl-list
[Top] [All Lists]

Formatting hyperlinks and paragraphs

2003-07-09 08:37:43
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



<Prev in Thread] Current Thread [Next in Thread>