clementsmc
MIS
My input file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<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="1.0" encoding="UTF-8"?>
<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 "DROP" event is received, I need to add two additional events to the XML file before uploading to my database and still keep the "DROP" event as well as all other events in the source file.
My XSL:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=" version="1.0" xmlns:lookup="
<xsl:template match="*|@*|comment()|processing-instruction()|text()">
<xsl:copy>
<xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="root/Event">
<xsl:choose>
<xsl:when test="@eventcode='DROP'">
<Event>
<eventdate><xsl:value-of select="@eventdate"/></eventdate>
<eventcode>EMPTY</eventcode>
</Event>
<xsl:apply-templates/>
<Event>
<eventdate><xsl:value-of select="@eventdate"/></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.
<?xml version="1.0" encoding="UTF-8"?>
<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="1.0" encoding="UTF-8"?>
<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 "DROP" event is received, I need to add two additional events to the XML file before uploading to my database and still keep the "DROP" event as well as all other events in the source file.
My XSL:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=" version="1.0" xmlns:lookup="
<xsl:template match="*|@*|comment()|processing-instruction()|text()">
<xsl:copy>
<xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="root/Event">
<xsl:choose>
<xsl:when test="@eventcode='DROP'">
<Event>
<eventdate><xsl:value-of select="@eventdate"/></eventdate>
<eventcode>EMPTY</eventcode>
</Event>
<xsl:apply-templates/>
<Event>
<eventdate><xsl:value-of select="@eventdate"/></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.