Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Assigning xml string using xsl:copy-of to xml:variable [Thread Next] Re: Assigning xml string using xsl:copy-of to xml:variableTo: NULL Date: 7/8/2004 9:20:00 AM "Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message news:<e0uitNAZEHA.3304@T...>...
> ms wrote:
>
> > I need, within the xsl, to send a fragment of the above xml as an
> > argument to a Javascript funtion:
> >
> > func('<a att1="dkjf"><b att2="dkf">John's</b><b
> > att2="dkf">Dave's</b></a>');
> >
> > The xml string first needs to have the " and ' output escaped. This
> > will need to be done using xsl so that I have the following instead:
> >
> > func('<a att1=\"dkjf\"><b att2=\"dkf\">John\'s</b><b
> > att2=\"dkf\">Dave\'s</b></a>');
> >
> > The problem I have is how to retrieve the full xml (elements included)
> > from the source xml.
>
> I see. The problem is that you need to serialize XML fragment to string.
> There is no such function in XSLT so you can either have extension
> function or implement serializing via templates:
>
> <xsl:template match="*" mode="serialize">
> <xsl:value-of select="concat('<', name())"/>
> <xsl:for-each select="@*">
> <xsl:value-of select="concat(' ', name(), '=\"', .,
> '\"')"/>
> </xsl:for-each>
> <xsl:text>></xsl:text>
> <xsl:apply-templates mode="serialize"/>
> <xsl:value-of select="concat('</', name(), '>')"/>
> </xsl:template>
> <xsl:template match="text()" mode="serialize">
> <!-- Implement replace in text here -->
> <xsl:value-of select="."/>
> </xsl:template>
>
> Alternatively consider using XML islands to avoid this stuff.
Thanks very much
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
