View Single Post
  #4 (permalink)  
Old July 15th, 2007, 09:44 PM
pauljr8 pauljr8 is offline
Registered User
 
Join Date: Jul 2007
Location: Palm Bay, FL, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to pauljr8
Default

Hi Ian,

I often want to display text exactly as I've entered it in an xml element. To do so I use this template and I've included an example of how I call it. So if I enter:
<tips name="Tip Number 1">
<tip>This is some

            text
I want displayed</tip>
<tip>of
course I
don't
really display
      anything
this way
</tip>
</tips>

It displays it that way. Hope it helps.

BTW I've had XSLT 2nd Edition Programmer's Reference for many years. Couldn't live without it, but I still need Mr. Kay's help from time to time. Stopped holding my breath to be able to use XSLT V. 2 when I looked like :(

<xsl:template match="tips">

<xsl:for-each select="./tip">

<h1 align="center"><xsl:value-of select="@name" /></h1>
<p>
<xsl:call-template name="replace-text">

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

      <xsl:with-param name="replace" select="'#10;'"/>

      <xsl:with-param name="by" select="'&lt;br /&gt;'"/>

    </xsl:call-template>
</p>
</xsl:for-each>

</xsl:template>


<xsl:template name="replace-text">

   <xsl:param name="text"/>

   <xsl:param name="replace" />

   <xsl:param name="by" />



   <xsl:choose>

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

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

      <xsl:value-of select="$by" disable-output-escaping="yes"/>

      <xsl:call-template name="replace-text">

         <xsl:with-param name="text" select="substring-after($text, $replace)"/>

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

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

      </xsl:call-template>

   </xsl:when>

   <xsl:otherwise>

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

   </xsl:otherwise>

   </xsl:choose>



</xsl:template>


Paul Hickey
Reply With Quote