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

Flatten xml

Status
Not open for further replies.

emmetmurray

Programmer
Feb 25, 2008
3
GB
Hi,

I need to flatten some xml, so that each element has only one tier after the root.

The current code is

- <event>

<event_token>MXJ</event_token>
<src_code>tptd</src_code>
<area_code>PAR</area_code>
<event_code>8441</event_code>
<venue_code>DIS/T</venue_code>
<country_code>fr</country_code>

<geographic_info>
<event_lattitude>48.87260000</event_lattitude>
<event_longitude>2.77170000</event_longitude>
</geographic_info>

<full_query>
<crypto_block>c_--bTWUoDG0GIgLYJ8muoe-UQ0YnVHRdRCDNJi8OhJ8svVB5QYbUuQe8vGHBShRH6yOQwrHzp N_APvUtz_L61fgJQvz3iDKMCyDC4cHb4CZmbs_GdEP-xN6zfSsCffUMvAu7GYnsP9Nnm2-Y</crypto_block>
</full_query>

</event>

I just need to get rid of the <geographic_info> and <full_query> tags, so that everything inside the <event> tag is only one level. So the out put should be:

- <event>

<event_token>MXJ</event_token>
<src_code>tptd</src_code>
<area_code>PAR</area_code>
<event_code>8441</event_code>
<venue_code>DIS/T</venue_code>
<country_code>fr</country_code>
<event_lattitude>48.87260000</event_lattitude>
<event_longitude>2.77170000</event_longitude>
<crypto_block>
c_--bTWUoDG0GIgLYJ8muoe-UQ0YnVHRdRCDNJi8OhJ8svVB5QYbUuQe8 vGHBShRH6yOQwrHzpN_APvUtz_L61fgJQvz3iDKMCyDC4cHb4C Zmbs_GdEP-xN6zfSsCffUMvAu7GYnsP9Nnm2-Y
</crypto_block>

</event>

I have very little knowledge of xslt and how to run the transformation, so any help at all would be greatful.

Thanks
 
The standard method of doing this is to use an identity transform and then put in specific templates to match the elements you wish to eliminate. See tsuji's post in thread426-1388253 for an example of the concept.

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top