xsl-list
[Top] [All Lists]

Re[2]: Formatting hyperlinks and paragraphs

2003-07-10 07:19:14
Hello Jeni,

Thursday, July 10, 2003, 5:06:08 AM, you wrote:

JT> 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?

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

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

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

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

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

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

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

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

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

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

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

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

JT> Cheers,

JT> Jeni

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


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


Good Morning Jeni;

A  quick  thank you. I'm going to go with your suggestion of combining
the  templates  and avoid using an extension. This is provin more of a
challenge than I had anticipated though.

I'm sure I'll have more questions shortly.

Thanks,

Pete





-- 

Peter 
mailto:peter(_at_)petersimard(_dot_)com



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



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