|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] flat xml to full tree with no repeating
I have a flat xml file that i'm trying to make into a tree format with
out repeats, and still keep all the child nodes.
the input xml file looks like..... <employees> <employee>
<uid>ceo</uid>
<manager-uid></manager-uid>
</employee> <employee>
<uid>vp-1</uid>
<manager-uid>ceo</manager-uid>
</employee> <employee>
<uid>vp-2</uid>
<manager-uid>ceo</manager-uid>
</employee> <employee>
<uid>vp-1-secratary</uid>
<manager-uid>vp-1</manager-uid>
</employee> <employee>
<uid>vp-1-assistant</uid>
<manager-uid>vp-1</manager-uid>
</employee> <employee>
<uid>vp-1-secratary2</uid>
<manager-uid>vp-1</manager-uid>
</employee> <employee>
<uid>vp-1-secretary2assistant</uid>
<manager-uid>vp-1-secratary2</manager-uid>
</employee>
</employees> -------- id like the output to look like.... <?xml version="1.0"?>
<nodes>
<node>
<top>ceo</top>
<node>
<bottom>vp-1</bottom>
<node>
<bottom>vp-1-assistant</bottom>
</node>
<node>
<bottom>vp-1-secratary</bottom>
</node>
<node>
<bottom>vp-1-secratary2</bottom>
<node>
<bottom>vp-1-secretary2assistant</bottom>
</node>
</node>
</node>
<node>
<bottom>vp-2</bottom>
<node>
<bottom>vp-2-secretary</bottom>
</node>
</node>
</node>
</nodes>
-------the xslt file im using makes it into a tree but i cant make it do the full grouping that i want. the xsl file looks like....... <?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:key name="all-reports" match="employee" use="manager-uid" /> <xsl:template match="employees"> <nodes> <xsl:for-each select="employee[generate-id() = generate-id(key('all-reports',manager-uid)[1])]"> <xsl:sort select="manager-uid" /> <xsl:if test="not(manager-uid = '')"> <node> <top><xsl:value-of select="manager-uid" /></top> <xsl:for-each select="key('all-reports', manager-uid)"> <xsl:sort select="uid" /> <node> <bottom><xsl:value-of select="uid" /></bottom> </node> </xsl:for-each> </node> </xsl:if> </xsl:for-each> </nodes> </xsl:template> </xsl:stylesheet> thanks in advance for your help
|
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
|

Cart








