Subject: [xsl] Formatting hyperlinks and paragraphs From: "Peter Simard" <peter@xxxxxxxxxxxxxxx> Date: Wed, 9 Jul 2003 11:37:43 -0400 |
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> </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> </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="'
'" /> <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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Expected token 'eof' enco, Michael Kay | Thread | [xsl] Formatting hyperlinks and par, Peter Simard |
Re: [xsl] xpath question, abbouh | Date | RE: [xsl] Expected token 'eof' enco, Tengshe, Ashish |
Month |