Subject: Re: [xsl] transforming a XML to CSV From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Wed, 14 Mar 2001 18:40:28 +0000 |
Hi Anand, > the kind of output which i am trying to achieve is something like : > ( i want HEADER ELEMENT to repeat with all DATA_ITEM ELELMENTS ) > > Venkatesh,1,US$,SPIN_PRICE,,,ZP26,20000512,24,F,0.25 > Venkatesh,1,US$,SPIN_PRICE,,,ZP26,20000512,25,T > Parigi,2,MW,SPIN_PRICE,,,ZP26,20000512,24,0.25 > Parigi,2,MW,SPIN_PRICE,,,ZP26,20000512,25,T The easiest way to do this is to apply templates to only the DATA elements within a template that <xsl:template match="REPORT_ITEM"> <xsl:apply-templates select="DATA" /> </xsl:template> Within the template for the DATA element, apply templates to the relevant HEADER element (which you can get to by going up to the DATA element's parent and then down again to the child HEADER element). Then give the data that you want for the particular DATA element: <xsl:template match="DATA"> <xsl:apply-templates select="../HEADER" /> <xsl:apply-templates /> </xsl:template> <!-- by default give the value followed by a comma --> <xsl:template match="DATA/*"> <xsl:value-of select="." />,<xsl:text /> </xsl:template> <!-- don't output anything for the NULL_FLAG element --> <xsl:template match="DATA/NULL_FLAG" priority="1" /> <!-- output the VALUE element if NULL_FLAG isn't 'T' --> <xsl:template match="DATA/VALUE" priority="1"> <xsl:choose> <xsl:when test="../NULL_FLAG = 'T'">T</xsl:when> <xsl:otherwise><xsl:value-of select="." /></xsl:otherwise> </xsl:choose> </xsl:template> Within the template for the HEADER element, output whatever you want to add from each HEADER. You can do this by applying templates to its content, as I've done for the content of the DATA element above, or (as you only want to know a bit of the contained data) it's probably simpler to just list them. You can get the number for the HEADER element using xsl:number: <xsl:template match="HEADER"> <xsl:value-of select="REPORT" />,<xsl:text /> <xsl:number level="any" />,<xsl:text /> <xsl:value-of select="UOM" />,<xsl:text /> </xsl:template> I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] transforming a XML to CSV, Awasthi, Anand | Thread | RE: [xsl] transforming a XML to CS, Evan Lenz |
[xsl] Is this a legal XPath Express, Phil Gooch | Date | Re: [xsl] retrive data from #1 xml , Jeni Tennison |
Month |