Re: [xsl] Formatting hyperlinks and paragraphs

Subject: Re: [xsl] Formatting hyperlinks and paragraphs
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 10 Jul 2003 10:06:08 +0100
Hi Peter,

> In a perfect world the stylesheet code below will take text from an
> xml element, and:
>
> 1)  transform  text  that begins with 'http' into hyperlinks
> 2) format the output to preserve line breaks.
>
> At the moment the code successfully formats the hyperlinks, but not
> line breaks. Hopefully someone can point out my error?

The problem in your stylesheet is that you add <br> elements as line
breaks in your text, and then process the root node of the result tree
fragment that you get, but you treat the root node as a string in the
text2hyper template, which means that all the <br> elements get lost.

You could change your stylesheet so that instead of passing the root
node of the result tree fragment to the text2hyper template, you apply
templates to it, in copy mode:

  <xsl:apply-templates select="msxsl:node-set($temp)" mode="copy" />

and have a template that copies the <br> elements:

<xsl:template match="br" mode="copy">
  <xsl:copy-of select="." />
</xsl:template>

and a template that matches the text nodes, and passes on their
content to be marked up as hyperlinks by your text2hyper template:

<xsl:template match="text()" mode="copy">
  <xsl:call-template name="text2hyper">
    <xsl:with-param name="strTemp" select="." />
  </xsl:call-template>
</xsl:template>

Alternatively you could combine the two templates. For example, rather
than just doing:

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

in the NewLine2Break template, you could call the text2hyper template
on that substring:

  <xsl:call-template name="text2hyper">
    <xsl:with-param name="strTemp"
                    select="substring-before($string, $from)" />
  </xsl:call-template>

Whether you want to do this probably depends on whether you'll ever
want to use NewLine2Break *without* adding hyperlinks to the lines,
and how bad you feel about using an extension function.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread