Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do You Insert XML Into an existing XML node

Tags:

I'm not even sure if it's possible but say I have some XML:

   <source>         <list>             <element id="1"/>         </list>     </source> 

And I would like to insert into list:

<element id="2"/> 

Can I write an XSLT to do this?

like image 471
warsze Avatar asked Sep 10 '08 16:09

warsze


1 Answers

Add these 2 template definitions to an XSLT file:

<xsl:template match="@*|node()">   <xsl:copy>     <xsl:apply-templates select="@*|node()"/>   </xsl:copy> </xsl:template> <xsl:template match="list">   <list>      <xsl:apply-templates select="@* | *"/>      <element id="2"/>   </list> </xsl:template>  
like image 98
Chris Marasti-Georg Avatar answered Oct 06 '22 00:10

Chris Marasti-Georg