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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit XML with XSL

Status
Not open for further replies.
Joined
Sep 9, 2002
Messages
4
Location
US
Here is my original XML Control file Map:

<root Delimiter=&quot;&quot; Type=&quot;FLAT&quot;>
<Rows StartWith=&quot;ship&quot; EndWith=&quot;&quot; ignore=&quot;&quot;>
<fileid>@fileid@</fileid>
<custcode>XXXX</custcode>
<reportedbyorg>XXXX</reportedbyorg>
<reporteddate date=&quot;yyyyMMddhhmm&quot;>X</reporteddate>
<tagfield1 position=&quot;5&quot; length=&quot;25&quot;>@flattext@</tagfield1>
<reportedatfacility position=&quot;87&quot; length=&quot;30&quot; database=&quot;lookup!value!section+subsection+key&quot;>XXXX+XXXX+@flattext@</reportedatfacility>
<reportedatother position=&quot;117&quot; length=&quot;30&quot;>@flattext@</reportedatother>
<note>From 214</note>
<isoformat>M</isoformat>
<Event>
<eventdate position=&quot;34&quot; length=&quot;19&quot;>@flattext@</eventdate>
<eventcode position=&quot;30&quot; length=&quot;2&quot; database=&quot;lookup!value!section+subsection+key&quot;>XXXX+XXXX+@flattext@</eventcode>
</Event>
</Rows>
</root>

What I'm trying to accomplish is: Copy the original file into the output XML file as well as when <eventcode> equals a specific value, insert two addtional <Event> nodes (with all inclusive children) into the output XML file.

Relatively new to XML/XSL. I have searched far and wide and can find only examples that apply to HTML output not XML.

Any and all suggestions would be most appreciated.

Thanks,

Mary
 
<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<xsl:transform
version=&quot;1.0&quot;
xmlns:xsl=&quot;<xsl:output method=&quot;xml&quot; indent=&quot;yes&quot;/>

<xsl:template match=&quot;*&quot;>
<xsl:copy>
<xsl:for-each select=&quot;@*&quot;>
<xsl:copy/>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

</xsl:transform>


that xsl should just print out a copy of the incoming file. i don't really understand what you want to add to the file but if you added a template like

<xsl:template match=&quot;note&quot;> that would override the * so adding

<xsl:template match=&quot;note&quot;>
<mynote><xsl:value-of select=&quot;.&quot;/></mynote>
</xsl:template>

to the xsl above would give you the same xml that you input but with all the <note> tags changed to <mynote>.

if this doesn't help in what you are trying to achieve then post some more details about the output.

tom.
 
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>
</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>
</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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top