Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: transform 0d0a to [Thread Next] Re: transform 0d0a to To: NULL Date: 5/19/2008 7:23:00 AM
"Martin Honnen" <mahotrash@y...> wrote in message
news:uRKv7m3tIHA.3968@T......
> Martin Honnen wrote:
>
>> I don't think the replace function will do what you want, it replaces
>> text with text while you seem to want to replace text with an element (a
>> br element). Sorry for not pointing that out earlier but I had not looked
>> at the context of your question, just at the question on how to use
>> node-set with MSXML 4.
>
> Here is an example on how to replace the characters with an element:
>
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>
> <xsl:output method="html" indent="yes"/>
>
> <xsl:param name="lb" select="' '"/>
>
> <xsl:template name="replace">
> <xsl:param name="text"/>
> <xsl:param name="str" select="$lb"/>
> <xsl:param name="name" select="'br'"/>
> <xsl:choose>
> <xsl:when test="contains($text, $str)">
> <xsl:value-of select="substring-before($text, $str)"/>
> <xsl:element name="{$name}"/>
> <xsl:call-template name="replace">
> <xsl:with-param name="text" select="substring-after($text,
> $str)"/>
> <xsl:with-param name="str" select="$str"/>
> <xsl:with-param name="name" select="$name"/>
> </xsl:call-template>
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="$text"/>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
> <xsl:template match="/">
> <html>
> <head>
> <title>Example</title>
> </head>
> <body>
> <xsl:apply-templates/>
> </body>
> </html>
> </xsl:template>
>
> <xsl:template match="paragraph">
> <p>
> <xsl:apply-templates/>
> </p>
> </xsl:template>
>
> <xsl:template match="text()">
> <xsl:call-template name="replace">
> <xsl:with-param name="text" select="."/>
> </xsl:call-template>
> </xsl:template>
>
> </xsl:stylesheet>
>
>
> When applied to this XML input
>
> <root>
> <paragraph>Line 1.
> Line 2.
> Line 3.</paragraph>
> </root>
>
> the result with MSXML 4 is
>
> <html>
> <head>
> <META http-equiv="Content-Type" content="text/html">
> <title>Example</title>
> </head>
> <body>
> <p>Line 1.
> <br>Line 2.
> <br>Line 3.</p>
> </body>
> </html>
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
It works great! Thank you.
LJB
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
