xslt convert xml string in xml elements -


here's tricky one.

i have following xml

<test>      <testelement someattribute="<otherxml><otherelement>test test</otherelement></otherxml>">       </testelement> </test> 

using xslt, want transform xml have following result.

<test>      <testelement>         <someattributetransformedtoelement>           <otherxml>                <otherelement>test test</otherelement>           </otherxml>         </someattributetransformedtoelement>       </testelement> </test> 

basically, text in attribute must transformed actual elements in final xml

any ideas how achieve in xslt?

alex

you can achieve disabling output escaping. however, note input document not valid xml document (< illegal in attribute values , needs escaping). therefore changed input document follows:

input document

<?xml version="1.0" encoding="utf-8"?> <test>   <testelement someattribute="&lt;otherxml>&lt;otherelement>test test&lt;/otherelement>&lt;/otherxml>">   </testelement> </test> 

xslt

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">    <xsl:output method="xml" indent="yes"/>    <xsl:template match="@* | node()">     <xsl:copy>       <xsl:apply-templates select="@* | node()"/>     </xsl:copy>   </xsl:template>    <xsl:template match="@someattribute">     <someattributetransformedtoelement>       <xsl:value-of select="." disable-output-escaping="yes"/>     </someattributetransformedtoelement>   </xsl:template> </xsl:stylesheet> 

be aware disable-output-escaping="yes" there no longer guarantee produced output document well-formed xml document.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -