www.webdeveloper.com
Results 1 to 2 of 2

Thread: Flatten xml

  1. #1
    Join Date
    Feb 2008
    Posts
    12

    Flatten xml

    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

  2. #2
    Join Date
    May 2007
    Posts
    288
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    	<xsl:template match="/*">
    		<xsl:copy>
    			<xsl:apply-templates/>
    		</xsl:copy>
    	</xsl:template>
    	<xsl:template match="*[text()]">
    		<xsl:copy-of select="."/>
    	</xsl:template>
    </xsl:stylesheet>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles