|
Subject: Re: [xsl] 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 |
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><</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>/></xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>></xsl:text>
<xsl:apply-templates select="node()"
mode="convert" />
<xsl:text></</xsl:text><xsl:value-of select="name(.)"
/>><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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] How does one convert an R, David Carlisle | Thread | Re: [xsl] How does one convert an R, David Carlisle |
| Re: [xsl] Passing parameters in XSL, JBryant | Date | Re: [xsl] really wysiwyg xsl editor, Dave Pawson |
| Month |