Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - embedding xml in xml as string [Thread Next] Re: embedding xml in xml as stringTo: NULL Date: 11/2/2005 7:14:00 PM In article
<shaun.roe-A3593D.13455602112005@n...>,
shaun roe <shaun.roe@w...> wrote:
it probably bad form to answer your own question, but I think this will
do it:
<!-- serializing the embedded xml into a string -->
<xsl:template name="serialize">
<xsl:param name="nodeset"/>
<!-- openstarttag, openendtag, closetag markers, and close empty tag
marker -->
<xsl:variable name="ot" select="'<'"/>
<xsl:variable name="oet" select="'</'"/>
<xsl:variable name="ct" select="'>'"/>
<xsl:variable name="cet" select="'/>'"/>
<xsl:for-each select="$nodeset">
<xsl:variable name="n" select="name()"/>
<xsl:variable name="value" select=".[not(./*)]"/>
<xsl:variable name="attributes">
<xsl:for-each select="./@*">
<xsl:call-template name="serializeAttribute"/>
</xsl:for-each>
</xsl:variable>
<xsl:choose>
<xsl:when test="empty(.)">
<xsl:value-of select="concat($ot,$n,$attributes,$cet,$LF)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($ot,$n,$attributes,$ct,$value)"/>
<xsl:call-template name="serialize">
<xsl:with-param name="nodeset" select="./*"/>
</xsl:call-template>
<xsl:value-of select="concat($oet,$n,$ct,$LF)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<!--serialize one attribute -->
<xsl:template name="serializeAttribute">
<xsl:variable name="q" select="'"'"/>
<xsl:variable name="an" select="name()"/>
<xsl:variable name="av" select="."/>
<xsl:value-of select="concat(' ',$an,'=',$q,$av,$q)"/>
</xsl:template>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
