Copy comments that are after the end of root tag using XSLT -


i have xml needs reordered , stored in file. have done xslt , works fine. if there comments after xml ends these comments not copied. need xslt statement copies comments present after root tag ends below code explains following

original xml

    <company>       <employee id="100" name="john" >         <salary value="15000"/>         <qualification text="engineering">         <state name="kerala" code="02">         <background text="indian">       </employee>     </company>  <!--this file contains employee information--> <!--please refer file information employee--> 

xslt transformation code

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"     xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">   <xsl:output indent="yes"  omit-xml-declaration="yes" method="xml" />   <xsl:strip-space elements="*"/>    <xsl:template match="@* | node()">     <xsl:copy>       <xsl:apply-templates select="@* | node()"/>     </xsl:copy>   </xsl:template>    <xsl:template match="employee">     <xsl:copy>       <xsl:apply-templates select="qualification"/>       <xsl:apply-templates select="salary" />       <xsl:apply-templates select="background"/>     </xsl:copy>   </xsl:template> </xsl:stylesheet> 

output obtained

<?xml version="1.0" encoding="utf-8"?> <company>   <employee>     <qualification text="engineering" />     <salary value="15000" />     <background text="indian" />   </employee> </company> 

output required

<?xml version="1.0" encoding="utf-8"?> <company>   <employee>     <qualification text="engineering" />     <salary value="15000" />     <background text="indian" />    </employee> </company>  <!--this file contains employee information--> <!--please refer file information employee--> 

there's nothing wrong transformation. ran same xslt on same xml (corrected make well-formed) using xsltproc , correct output including trailing comments (though have lost original indentation , spacing due strip-space , indent="yes" in stylesheet)

<company>   <employee>     <qualification text="engineering"/>     <salary value="15000"/>     <background text="indian"/>   </employee> </company><!--this file contains employee information--> <!--please refer file information employee--> 

it looks whatever processor or xml parser you're using (presumably microsoft 1 judging xmlns:msxsl="urn:schemas-microsoft-com:xslt") ignoring comments after end tag of document element.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -