[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to generate multiple rows based on sub element

Subject: Re: How to generate multiple rows based on sub element
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Thu, 24 Sep 2009 17:20:57 +0200
Re:  How to generate multiple rows based on sub element
abhilash k wrote:

We are using XSLT 1.0 and have to map XML to a CSV file, the input looks like this <Message> <Work>Contract</Work> <Timesheet>Approved</Timesheet> <Days> <Mon>8</Mon> <Tues>7</Tues> <Fri>9</Fri> </Days> </Message> In the output depending on the days worked we need to generate multiple rows. ie the XSLT logic for all other fields will remain the same (Work, Timesheet etc), the logic will change only for field 'Days'...any inputs on how to accomplish this in XSLT
Expected Output: ------------------------- Work, Timesheet, Days, Hours Contract, Approved, Mon, 8 Contract, Approved, Tues, 7 Contract, Approved, Fri, 9

This stylesheet should do:


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

<xsl:output method="text"/>

  <xsl:param name="sep" select="', '"/>
  <xsl:param name="lf" select="'&#13;&#10;'"/>

<xsl:template match="/">
<xsl:value-of select="concat('Work', $sep, 'Timesheet', $sep, 'Days', $sep, 'Hours', $lf)"/>
<xsl:for-each select="Message/Days/*">
<xsl:value-of select="concat(../../Work, $sep, ../../Timesheet, $sep, name(), $sep, ., $lf)"/>
</xsl:for-each>
</xsl:template>


</xsl:stylesheet>
--

	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.