[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] XSLT hierarchy to flat
hi all, I am attempting to transform a XML document ( which is exported to me) from a hierarchical to flat structure. However i am having problems with the repeating elements at the same level. ie. elements<intersection> <section>. It is easier if the problem is illustrated. Both the XML and XSL are below. My problem is that the 2 for-each loops produce output like <row><col1>51.658936</col1><col2>-0.252627</col2><col3>BORE</col3><col4>ahea d</col4></row> <row><col1>51.654978</col1><col2>-0.24951</col2><col3>BORE</col3><col4>ahead </col4></row> <row><col5>A1201</col5></row> <row><col5>COMPTON</col5></row> I require the output of <row><col1>51.658936</col1><col2>-0.252627</col2><col3>BOREHAMWOOD</col3><co l4>ahead</col4></row><col5>A1201</col5></row> The ideal solution would be to have the XML defining a parent element of <intersection> and <section> but the XML is exported to me. Firstly can XSLT solve this problem? If so any help is appreciated. -------------XSL----------------------- <xsl:template match="/"> <xsl:for-each select="//intersection"> <row> <xsl:call-template name="intersection_template"/> </row> </xsl:for-each> <xsl:for-each select="//section"> <row1> <xsl:call-template name="section_template"/> </row1> </xsl:for-each> </xsl:template> <xsl:template name="section_template"> <col5> <xsl:value-of select="name"/> </col5> </xsl:template> <xsl:template name="intersection_template"> <col1> <xsl:value-of select="navid/@latitude"/> </col1> <col2> <xsl:value-of select="navid/@longitude"/> </col2> <col3> <xsl:value-of select="location"/> </col3> <col4> <xsl:value-of select="direction"/> </col4> </xsl:template> ----------------XML------------------- <intersection> <navid latitude="51.658936" longitude="-0.252627" /> <location>BOREHAMWOOD</location> <direction>ahead</direction> </intersection> <section type="road" level="1" length="898" realtime="171" fixedtime="171"> <name>A5135</name> </section> <intersection> <navid latitude="51.654978" longitude="-0.24951" /> <location>BOREHAMWOOD</location> <direction>ahead</direction> <ramp /> </intersection> <section type="road" level="1" length="18412" realtime="1753" fixedtime="1753"> <name>A1</name> </section> adios -lucio --------------------------------------------------------------------- LUCIO.PICCOLI@o... Elstree Tower Elstree Way Borehamwood tel : +44 208 214 3847 fax :+44 208 214 2325 HERTS WD6 1DT __________ http://www.one2one.co.uk _____________ NOTICE AND DISCLAIMER: This email (including attachments) is confidential. If you have received this email in error please notify the sender immediately and delete this email from your system without copying or disseminating it or placing any reliance upon its contents. We cannot accept liability for any breaches of confidence arising through use of email. Any opinions expressed in this email (including attachments) are those of the author and do not necessarily reflect our opinions. We will not accept responsibility for any commitments made by our employees outside the scope of our business. We do not warrant the accuracy or completeness of such information.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|