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

Re: How does one convert an RTF to a string?

Subject: Re: How does one convert an RTF to a string?
From: Kenneth Stephen <marvin.the.cynical.robot@xxxxxxxxx>
Date: Thu, 9 Jun 2005 12:56:11 -0500
convert text to rtf
Hi,

    A search in the FAQ and elsewhere didnt turn up what I was looking
for. So here is my first pass :

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
        xmlns:xalan="http://xml.apache.org/xalan"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">



        <xsl:template match="/">

                <xsl:variable name="rtf">
                                <node>
                                        <!-- Here is a comment -->

                                        <child attrib="something"
>value</child>
                                </node>
                </xsl:variable>

                <xsl:variable name="tmpStr">
                <xsl:apply-templates select="xalan:nodeset($rtf)"
mode="convert" />
                </xsl:variable>
                <xsl:value-of select="$tmpStr" disable-output-escaping="yes"
/>

        </xsl:template>

        <xsl:template match="*" mode="convert">
                <xsl:text>&lt;</xsl:text><xsl:value-of
select="name(.)" /><xsl:text />
                <xsl:for-each select="@*">
                        <xsl:text> </xsl:text><xsl:value-of
select="name(.)" />="<xsl:value-of select="." />"<xsl:text />
                </xsl:for-each>
                <xsl:choose>
                        <xsl:when test="count(node()) = 0">
                                <xsl:text>/&gt;</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                                <xsl:text>&gt;</xsl:text>
                                <xsl:apply-templates select="node()"
mode="convert" />

<xsl:text>&lt;/</xsl:text><xsl:value-of select="name(.)"
/>&gt;<xsl:text />
                        </xsl:otherwise>
                </xsl:choose>
        </xsl:template>

        <xsl:template match="text()" mode="convert">
                <xsl:text/><xsl:value-of select="." /><xsl:text />
        </xsl:template>

        <xsl:template match="comment()" mode="convert">
                <xsl:comment><xsl:value-of select="." /></xsl:comment>
        </xsl:template>

</xsl:stylesheet>

    Unfortunately, this produces the output :

<?xml version="1.0" encoding="UTF-8"?>
<node><child attrib="something">value</child></node>

    Why am I not getting the whitepsaces in my RTF or the comments?

Thanks,
Kenneth

On 6/9/05, David Carlisle <davidc@xxxxxxxxx> wrote:
>     How can I do this? Will I have to write an XML serializer in XSL
>     or is there an easier way?
>
> Yes, if you generate a node tree in the RTF then you'll have to use
> x:node-set() to get the nodes back and then use templates or an
> extesnion function to serialise the tree as a string. There are several
> existing templates to do this in the faq or in the archives of this list.

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.