Output escaped xml in an attribute in an xslt -


input xml:

<parent>     <child attr="thing">stuff</child> </parent> 

xslt:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">     <xsl:template match="child">         <newchild chars="{..}" />     </xsl:template> </xsl:stylesheet> 

desired otuput:

<newchild chars="&lt;child attr=&quot;thing&quot;&gt;stuff&lt;/child&gt;" /> 

note value of 'chars' attribute escaped version of 'child' tag.

problem: how matched element in attribute? though .. it, seems not when talking attributes, random xml entities followed value of child tag e.g. <newchild chars="&#xa; stuff&#xa;"/>. i'm expecting there might need escaping stuff make valid.

any suggestions appreciated.

(and before asks why i'd want this, i'm constrained api of application i'm connecting to)

it looks have build bit bit. note .. points parent. want want create "&lt;child attr=&quot;", append <value-of select='@attr'/>, "&gt;", <value-of select="."/> , "&lt;/child>", concatenate of them , create chars attribute using <xsl:attribute/>

something like:

   <newchild >      <xsl:attribute name="chars">&lt;child attr=&quot;<xsl:value-of select="@attr"/>"&gt;"<value-of select="."/>&lt;/child&gt;</xsl:attribute>    </newchild> 

haven't checked hope helps.

however error-prone. if had this, i'd not use xslt, dom has "toxml()" method , run escapexml() on it.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -