[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] SV: Fwd: Flat XML File to Hierarchical ... best approa
I guess you can modify this suggestion to achieve what you want. <xsl:template match="/Items"> <xsl:element name="Items"> <xsl:apply-templates select="//Item[ParentID='0000']"> <xsl:with-param name="level" select="1"/> </xsl:apply-templates> </xsl:element> </xsl:template> <xsl:template match="Item"> <xsl:param name="level"/> <xsl:element name="{concat(name(), $level)}"> <xsl:copy-of select="*"/> <xsl:apply-templates select="//Note[ParentID=current()/DocumentItemID]"/> <xsl:apply-templates select="//Item[ParentID=current()/DocumentItemID]"> <xsl:with-param name="level" select="$level + 1"/> </xsl:apply-templates> </xsl:element> </xsl:template> <xsl:template match="Note"> <xsl:copy-of select="."/> </xsl:template> As you see this solution finds an Item element and processes it's logical Note and Item children by applying templates with a modified selection. (The first template identifies the top node(s), you might have other search criterias here.) - Per Osnes. -----Opprinnelig melding----- Fra: Mary McRae [mailto:fiberartisan@xxxxxxxxx] Sendt: 19. november 2006 01:56 Til: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Emne: Fwd: Flat XML File to Hierarchical ... best approach? First, I've been to the FAQ site and read each of the entries of Flat File to Hierarchical. I didn't find anything that quite addressed my problem. My source data is flat but properly sequenced. There are two elements whose values, if identical, imply parent/child relationship -- DocumentItemID and ParentID. Input XML: <Items> <Item> (should correspond to Items/Item) <DocumentItemID>aaaaa</DocumentItemID> <ParentID>0000</ParentID> ... </Item> <Note> (should correspond to Items/Item/Note) <DocumentItemID>11111</DocumentItemID> <ParentID>aaaaa</ParentID> ... </Note> <Item> (should correspond to Items/Item/Item) <DocumentItemID>bbbbb</DocumentItemID> <ParentID>aaaaa</ParentID> ... </Item> <Item> (should correspond to Items/Item/Item/Item) <DocumentItemID>ccccc</DocumentItemID> <ParentID>bbbbb</ParentID> ... </Item> Output XML: <Item1> <DocumentItemID>aaaaa</DocumentItemID> <ParentID>0000</ParentID> ... <Note> <DocumentItemID>11111</DocumentItemID> <ParentID>aaaaa</ParentID> ... </Note> <Item2> <DocumentItemID>bbbbb</DocumentItemID> <ParentID>aaaaa</ParentID> ... <Item3> <DocumentItemID>ccccc</DocumentItemID> <ParentID>bbbbb</ParentID> ... </Item3> </Item2> </Item1> </Items> There can be as many as 8 levels of Item. There are 4 other elements that are similar to Note and must always be a child of an Item(1-8) element. My thought was that I could capture the Item/DocumentItemID each time I encounter an Item element, and then each time I encounter a Note or other child element of Item compare its child ParentID to the Item/DocumentID and if they match output the child elements ... I keep either suppressing output of everything but the Item elements or repeating the Note elements in each instance of an Item element ... Can someone point me in the right direction? Thanks! Judy
|
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
|