[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Text markup for web forums, eg. [b]bold text[/b]

Subject: RE: Text markup for web forums, eg. [b]bold text[/b]
From: "Daniel Joshua" <daniel.joshua@xxxxxxxxxxxx>
Date: Tue, 1 Jun 2004 15:51:27 +0800
joshua daniel
I was reading through this, gave me some ideas.

Except that it does not handle nested "markup" like my input (below).

> XML (input):
>
>  <text>
>    <value>Text may contain [b]bold text[/b], [i]italics[/i] or both
> [b][i]bold and italics[/i][/b].</value>
>  </text>

The reason for this is that it assumes that the first occurence of the end
tag "[/..."
will match the current start tag, and this is not true in "[b][i]bold and
italics[/i][/b]".

> <xsl:with-param name="content"
> select="substring-after(substring-before($processText, '[/'), ']')"/>

Also, there's no checking that the end tag matches the start tag.

But, I am much closer to my solution now. Thanks Mark!


Regards,
Daniel

-----Original Message-----

Re:  UBB Code and XSLT
Subject: Re:  UBB Code and XSLT
From: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Sat, 10 Jan 2004 16:10:29 -0700


Ive been working on creating an XSLT parser that can parse random text and
seek out certain words or phrases and recursively apply styles to them at
will.  It's a little rough around the edges but it was fairly simple to
apply the concept to UBB.  Anyway, I didn't go after every element and the
URL one without the [url][/url] tag will take a little effort but it is
possible... I eventually will convert this into a template that looks for
words and phrases that are stored in XML and stylized accordingly using a
couple associated attributes...  But time is short and the work is big so
thatll have to be another day.

Anyway, enjoy... hopes this helps get your party started...

Best regards,

M.

The following UBB wrapped into and XML wrapper (there are many ways to do
that on the fly)

*******************************************
<?xml version="1.0"?>

<content>
 <ubb>
  This is a test of UBB.
  [b]this is test of bold[/b]
  [i]this is a test of italic[/i]
  [email]m.david@xxxxxxxxxx[/email]
  [QUOTE]this is a quote[/QUOTE]
  [url]http://www.thissucks.com[/url]
 </ubb>
</content>

*******************************************

And then transformed by the following XSLT...

********************************************
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
<xsl:preserve-space elements="*"/>

<xsl:output method="html"/>

<xsl:template match="/">
 <xsl:call-template name="capture">
  <xsl:with-param name="processText" select="content/ubb"/>
 </xsl:call-template>
</xsl:template>

<xsl:template name="capture">
 <xsl:param name="processText"/>
 <xsl:variable name="remainingContent" select="$processText"/>
 <xsl:variable name="remaining_after_end_ubb"
select="substring-after($processText, '[/')"/>
 <xsl:variable name="remainingContent_after_ubb"
select="substring-after($remaining_after_end_ubb, ']')"/>
  <xsl:choose>
   <xsl:when test="not(starts-with($processText, '['))">
    <xsl:value-of select="substring-before($processText, '[')"/>
    <xsl:call-template name="capture">
     <xsl:with-param name="processText" select="concat('[',
substring-after($processText, '['))"/>
    </xsl:call-template>
   </xsl:when>
   <xsl:when test="contains($processText, '[')">
    <xsl:call-template name="processUBB">
     <xsl:with-param name="ubbType"
select="substring-after(substring-before($processText, ']'), '[')"/>
     <xsl:with-param name="content"
select="substring-after(substring-before($processText, '[/'), ']')"/>
     <xsl:with-param name="remainingContent"
select="$remainingContent_after_ubb"/>
    </xsl:call-template>

   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="$remainingContent"/>
   </xsl:otherwise>
  </xsl:choose>

</xsl:template>

<xsl:template name="processUBB">

<xsl:param name="ubbType"/>
<xsl:param name="content"/>
<xsl:param name="remainingContent"/>

 <xsl:choose>
  <xsl:when test="$ubbType = 'b'">
   <xsl:call-template name="b">
    <xsl:with-param name="remainingContent" select="$remainingContent"/>
    <xsl:with-param name="content" select="$content"/>
   </xsl:call-template>
  </xsl:when>
  <xsl:when test="$ubbType = 'i'">
   <xsl:call-template name="i">
    <xsl:with-param name="remainingContent" select="$remainingContent"/>
    <xsl:with-param name="content" select="$content"/>
   </xsl:call-template>
  </xsl:when>
  <xsl:when test="$ubbType = 'img'">
   <xsl:call-template name="img">
    <xsl:with-param name="remainingContent" select="$remainingContent"/>
    <xsl:with-param name="content" select="$content"/>
   </xsl:call-template>
  </xsl:when>
  <xsl:when test="$ubbType = 'email'">
   <xsl:call-template name="email">
    <xsl:with-param name="remainingContent" select="$remainingContent"/>
    <xsl:with-param name="content" select="$content"/>
   </xsl:call-template>
  </xsl:when>
  <xsl:when test="$ubbType = 'QUOTE'">
   <xsl:call-template name="QUOTE">
    <xsl:with-param name="remainingContent" select="$remainingContent"/>
    <xsl:with-param name="content" select="$content"/>
   </xsl:call-template>
  </xsl:when>
  <xsl:when test="$ubbType = 'url'">
   <xsl:call-template name="url">
    <xsl:with-param name="remainingContent" select="$remainingContent"/>
    <xsl:with-param name="content" select="$content"/>
   </xsl:call-template>
  </xsl:when>
  <xsl:otherwise>
   <xsl:call-template name="capture">
    <xsl:with-param name="remainingContent" select="$remainingContent"/>
    <xsl:with-param name="content" select="$content"/>
   </xsl:call-template>
  </xsl:otherwise>
 </xsl:choose>

</xsl:template>

<xsl:template name="b">
<xsl:param name="content"/>
<xsl:param name="remainingContent"/>
 <b><xsl:value-of select="$content"/></b>
 <xsl:call-template name="capture">
  <xsl:with-param name="processText" select="$remainingContent"/>
 </xsl:call-template>
</xsl:template>

<xsl:template name="i">
<xsl:param name="content"/>
<xsl:param name="remainingContent"/>
 <i><xsl:value-of select="$content"/></i>
 <xsl:call-template name="capture">
  <xsl:with-param name="processText" select="$remainingContent"/>
 </xsl:call-template>
</xsl:template>

<xsl:template name="email">
<xsl:param name="content"/>
<xsl:param name="remainingContent"/>
 <a href="mailto:{$content}";;><xsl:value-of select="$content"/></a>
 <xsl:call-template name="capture">
  <xsl:with-param name="processText" select="$remainingContent"/>
 </xsl:call-template>
</xsl:template>

<xsl:template name="img">
<xsl:param name="content"/>
<xsl:param name="remainingContent"/>
 <img src="{$content}"/>
 <xsl:call-template name="capture">
  <xsl:with-param name="processText" select="$remainingContent"/>
 </xsl:call-template>
</xsl:template>

<xsl:template name="QUOTE">
<xsl:param name="content"/>
<xsl:param name="remainingContent"/>
 "<xsl:value-of select="$content"/>"
 <xsl:call-template name="capture">
  <xsl:with-param name="processText" select="$remainingContent"/>
 </xsl:call-template>
</xsl:template>

<xsl:template name="url">
<xsl:param name="content"/>
<xsl:param name="remainingContent"/>
 <a href="{$content}"><xsl:value-of select="$content"/></a>
 <xsl:call-template name="capture">
  <xsl:with-param name="processText" select="$remainingContent"/>
 </xsl:call-template>
</xsl:template>

</xsl:stylesheet>

********************************************

Will recursively crawl the UBB text of the XML node and produce this...

*******************************************


  This is a test of UBB.
  <b>this is test of bold</b>
  <i>this is a test of italic</i>
  <a href="mailto:m.david@xxxxxxxxxx";;>m.david@xxxxxxxxxx</a>

 "this is a quote"

  <a href="http://wwwthissucks.com";>http://www.thissucks.com</a>


**************************************************


Have a good one!

| M. David Peterson mark.peterson@xxxxxxxxxxx |



-----Original Message-----
From: M. David Peterson [mailto:m.david@xxxxxxxxxx]
Sent: Tuesday, 01 June, 2004 2:51 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Text markup for web forums, eg. [b]bold text[/b]


Hey Daniel,

Heres a solution I posted a while back that will solve your problem...

http://www.biglist.com/lists/xsl-list/archives/200401/msg00337.html

Hope this helps!

<M:D/>


----- Original Message -----
From: "Daniel Joshua" <daniel.joshua@xxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Tuesday, June 01, 2004 12:25 AM
Subject:  Text markup for web forums, eg. [b]bold text[/b]


> Hi all,
>
> I am trying to use XSL to do the common mark-up found in web forums,
> etc (I am making my own mini-forum integrated into my application).
>
>
>
> XML (input):
>
>  <text>
>    <value>Text may contain [b]bold text[/b], [i]italics[/i] or both
> [b][i]bold and italics[/i][/b].</value>
>  </text>
>
> (X)HTML (desired output):
>
>  <div class="text">Text may contain <b>bold text</b>, <i>italics</i> or
> both <b><i>bold and italics</i></b>.</div>
>
>
> XSLT (incomplete):
>
>  <xsl:template match="text">
>    <div class="text">
>      <xsl:value-of select="value"/>
>    </div>
>  </xsl:template>
>
>
> I am stumped on how to continue... maybe just give me some
> ideas and I will continue from there...
>
> Also, how should I handle incomplete or wrongly nested tags
> (eg. <value>[b]blah blah [b][i]blah blah[/b][/i]</value>)
>
> Most web forums normally just do not convert "bad" tags and
> leave them for users to edit and fix them, so I guess I
> should try to do the same.
>
>
> Regards,
> Daniel


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.