Adding nodes to XML output using XSLT

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I want to add some new nodes to some XML output via XSLT. I have made some progress by using these forums but I have come across a problem.

I am trying to get this XML:

<dataroot>
<span style="white-space:pre <JOB>
<span style="white-space:pre <JOBDETAILS xmlns:od="urn:schemas-microsoft-com:officedata
<span style="white-space:pre <JOBID>12699</JOBID>
<span style="white-space:pre </JOBDETAILS>
<span style="white-space:pre <ADDRESS xmlns:od="urn:schemas-microsoft-com:officedata
<span style="white-space:pre <TYPE>Insured</TYPE>
<span style="white-space:pre </ADDRESS>
<span style="white-space:pre </JOB>
<dataroot>

To look like this:

<dataroot>
<span style="white-space:pre <JOB>
<span style="white-space:pre <JOBDETAILS xmlns:od="urn:schemas-microsoft-com:officedata
<span style="white-space:pre <JOBID>12699</JOBID>
<span style="white-space:pre </JOBDETAILS>
<span style="white-space:pre <JOBADDRESSES>
<span style="white-space:pre <span style="white-space:pre
<ADDRESS xmlns:od="urn:schemas-microsoft-com:officedata
<TYPE>Insured</TYPE>
</ADDRESS>
</JOBADDRESSES>
</JOB>
<dataroot>


I am trying to add <JOBADDRESSES> above the <ADDRESS> node.

My transform file looks like this:

<?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="dataroot
<dataroot>
<JOB>
<xsl:copy-of select="*"/>
</JOB>
</dataroot>
</xsl:template>

<xsl:template match="ADDRESS
<JOBADDRESSES>
<ADDRESS>
<xsl:copy-of select="*"/>
</ADDRESS>
</JOBADDRESSES>
</xsl:template>

</xsl:stylesheet>

As you can see I am already adding the <JOB> node which works fine. But if I try to add the <JOBADDRESSES> node nothing happens. I have tried to use the location code example here: http://social.msdn.microsoft.com/Forums/en/xmlandnetfx/thread/8722b40c-ff7d-4f51-bc70-aacdbced592c http://social.msdn.microsoft.com/Forums/en/xmlandnetfx/thread/8722b40c-ff7d-4f51-bc70-aacdbced592c which
has been helpful but for some reason I cannot get the second node transform to work. What I want to happen is very similar - as far as I can see - identical to this example but it doesnt work for me. I have tried changing the transform so that the first node
<JOB> is changed by using <span style="font-family:Consolas; font-size:13px; line-height:16px <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial <<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#2b91af; padding:0px; margin:0px; border:0px initial initial xsl:apply-templates <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:red; padding:0px; margin:0px; border:0px initial initial select<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial ="<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial *"<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial /> instead
of <span style="font-family:Consolas; font-size:13px; line-height:16px <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial <<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#2b91af; padding:0px; margin:0px; border:0px initial initial xsl:copy-of <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:red; padding:0px; margin:0px; border:0px initial initial select<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial ="<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial *"<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial /> but
that messes the whole output up and breaks the <JOBDETAILS> node altogether. What is it I am doing wrong?
<br/>
<br/>

View the full article
 
Back
Top