Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML to XML - Adding Nodes

Status
Not open for further replies.
Sep 9, 2002
4
US
My input file looks like:

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<root>
<Rows><fileid>100027</fileid>
<custcode>WINNDIXIE</custcode>
<reportedbyorg>GST</reportedbyorg>
<reporteddate>200209130909</reporteddate>
<tagfield1>01269695</tagfield1>
<reportedatfacility>3205</reportedatfacility>
<reportedatother/>
<note>From GST 214</note>
<isoformat>M</isoformat>
<Event>
<eventdate>200209120800</eventdate>
<eventcode>DROP</eventcode>
</Event>
<Event>
<eventdate>200209080800</eventdate>
<eventcode>SHIPSTART</eventcode>
</Event>

</Rows>
</root>

I need my output file to look like:

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<root>
<Rows><fileid>100027</fileid>
<custcode>WINNDIXIE</custcode>
<reportedbyorg>GST</reportedbyorg>
<reporteddate>200209130909</reporteddate>
<tagfield1>01269695</tagfield1>
<reportedatfacility>3205</reportedatfacility>
<reportedatother/>
<note>From GST 214</note>
<isoformat>M</isoformat>
<Event><eventdate>200209120800</eventdate>
<eventcode>DROP</eventcode>
</Event>
<Event><eventdate>200209120800</eventdate>
<eventcode>EMPTY</eventcode>
</Event>
<Event><eventdate>200209120800</eventdate>
<eventcode>EMPTYRET</eventcode>
</Event>
</Event>
<Event><eventdate>200209080800</eventdate>
<eventcode>SHIPSTART</eventcode>
</Event>
</Rows>
</root>

Whenever the &quot;DROP&quot; event is received, I need to add two additional events to the XML file before uploading to my database and still keep the &quot;DROP&quot; event as well as all other events in the source file.

My XSL:

<?xml version=&quot;1.0&quot;?>
<xsl:stylesheet xmlns:xsl=&quot; version=&quot;1.0&quot; xmlns:lookup=&quot;
<xsl:template match=&quot;*|@*|comment()|processing-instruction()|text()&quot;>
<xsl:copy>
<xsl:apply-templates select=&quot;*|@*|comment()|processing-instruction()|text()&quot;/>
</xsl:copy>
</xsl:template>


<xsl:template match=&quot;root/Event&quot;>
<xsl:choose>
<xsl:when test=&quot;@eventcode='DROP'&quot;>
<Event>
<eventdate><xsl:value-of select=&quot;@eventdate&quot;/></eventdate>
<eventcode>EMPTY</eventcode>
</Event>
<xsl:apply-templates/>
<Event>
<eventdate><xsl:value-of select=&quot;@eventdate&quot;/></eventdate>
<eventcode>EMPTYRET</eventcode>
</Event>
<xsl:apply-templates/>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

Any suggestions would be most appreciated. New to XSL and cannot seem to wrap my brain around this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top