xsl-list
[Top] [All Lists]

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

2004-06-01 03:31:12
Hi David,

How about translating also <> to [] in the first pass and apply in a second pass a copy stylesheet with the output method set to xml this time that will translate the [] back to <> ?

<?xml version="1.0" encoding="UTF-8"?>
<text>
<value>Text may &lt; contain [b]bold text[/b], [i]italics[/i] or both
[b][i]bold and italics[/i][/b].</value>
</text>

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
    <xsl:output method="text"/>
    <xsl:template match="/">
       <xsl:text>&lt;processedValue&gt;</xsl:text>
       <xsl:value-of select="translate(text/value, '[]&lt;>', '&lt;>[]')"/>
       <xsl:text>&lt;/processedValue&gt;</xsl:text>
    </xsl:template>
</xsl:stylesheet>


<processedValue>Text may [ contain <b>bold text</b>, <i>italics</i> or both
<b><i>bold and italics</i></b>.</processedValue>


<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
    <!-- Match document -->
    <xsl:template match="/">
        <xsl:apply-templates mode="copy" select="."/>
    </xsl:template>
    <!-- Deep copy template -->
    <xsl:template match="*|@*" mode="copy">
        <xsl:copy>
            <xsl:apply-templates mode="copy" select="@*"/>
            <xsl:apply-templates mode="copy"/>
        </xsl:copy>
    </xsl:template>
    <!-- process the [] from text nodes -->
    <xsl:template match="text()" mode="copy">
        <xsl:value-of select="translate(., '[]', '&lt;>')"/>
    </xsl:template>
</xsl:stylesheet>


<?xml version="1.0" encoding="UTF-8"?>
<processedValue>Text may &lt; contain <b>bold text</b>, <i>italics</i> or both
<b><i>bold and italics</i></b>.</processedValue>

Best Regards,
 George
-----------------------------------------------
George Cristian Bina
<oXygen/> XML Editor & XSLT Editor/Debugger
http://www.oxygenxml.com


M. David Peterson wrote:
In rethinking through this and then testing it it occured to me that this solution creates some issues with output escaping. Ive got to attend to some other things this morning but will take a look at this again later.

Best regards,

<M:D/>

----- Original Message ----- From: "M. David Peterson" 
<m(_dot_)david(_at_)mdptws(_dot_)com>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Tuesday, June 01, 2004 2:47 AM
Subject: Re: [xsl] Text markup for web forums, eg. [b]bold text[/b]


Sometimes the most obvious solutions are the ones that get overlooked. Although you would obviously have to process this further for tags like [QUOTE] and [email]. But once the conversion to XML has taken place thats obviously not an issue.

Give me a sec to update the code and Ill repost a much more elegant solution.

Thanks George!

<M:D/>