[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Solution Needed for DB output
balaganesh mohan wrote:
I am very new to xslt and i know basics of xslt only. Assuming the XML input is <getMatrixOutputCllection> <outputVar> <level_id>1</level_id> <assignee>jcooper</assignee> <reg>1000</reg> <gold>2000</gold> <sublevel>1</sublevel> <status>approve</status> </outputVar> <outputVar> <level_id>1</level_id> <assignee>jcooper</assignee> <reg>1000</reg> <gold>2000</gold> <sublevel>1</sublevel> <status>reject</status> </outputVar> <outputVar> <level_id>1</level_id> <assignee>jcooper</assignee> <reg>1000</reg> <gold>2000</gold> <sublevel>2</sublevel> <status>pending</status> </outputVar>
<outputVar> <level_id>1</level_id> <assignee>jcooper</assignee> <reg>1000</reg> <gold>2000</gold> <sublevel>3</sublevel> <status>no</status> </outputVar>
<outputVar> <level_id>2</level_id> <assignee>jstein</assignee> <reg>6000</reg> <gold>4000</gold> <sublevel>2</sublevel> <status>pending</status> </outputVar> </getMatrixOutputCllection> then this XSLT stylesheet <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:key name="lv" match="outputVar" use="level_id"/> <xsl:key name="sl" match="sublevel" use="concat(parent::outputVar/level_id, '|', .)"/> <xsl:template match="/*"> <xsl:copy> <xsl:apply-templates select="outputVar[generate-id() = generate-id(key('lv', level_id)[1])]"/> </xsl:copy> </xsl:template> <xsl:template match="outputVar"> <xsl:copy-of select="level_id | assignee | reg | gold"/> <xsl:apply-templates select="key('lv', level_id)/sublevel[generate-id() = generate-id(key('sl', concat(parent::outputVar/level_id, '|', .))[1])]"/> </xsl:template> <xsl:template match="sublevel"> <xsl:copy-of select="."/> <xsl:copy-of select="key('sl', concat(parent::outputVar/level_id, '|', .))/following-sibling::status[1]"/> </xsl:template> </xsl:stylesheet> creates the following output: <getMatrixOutputCllection> <level_id>1</level_id> <assignee>jcooper</assignee> <reg>1000</reg> <gold>2000</gold> <sublevel>1</sublevel> <status>approve</status> <status>reject</status> <sublevel>2</sublevel> <status>pending</status> <sublevel>3</sublevel> <status>yes</status> <status>no</status> <level_id>2</level_id> <assignee>jstein</assignee> <reg>6000</reg> <gold>4000</gold> <sublevel>1</sublevel> <status>go</status> <sublevel>2</sublevel> <status>proceed</status> <status>pending</status> </getMatrixOutputCllection> -- Martin Honnen http://msmvps.com/blogs/martin_honnen/
|
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
|