|
[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Ugly XML processing looking for a generic XML solution (long)
Michel Rodriguez asked about restructuring a flat document with xslt - > > The initial XML is something like: > > <doc> > <!-- stuff --> > <!-- there are actually _NO_ comments in the file --> > <!-- names have been changed to protect the identity of the victims--> > <person er="officer">Ms Foo</person> > <person er="officer">Mr Bar</person> > <person>Mss Toto</person> > <person>Dr Tata</person> > <!-- other stuff --> > </doc> > > And I want a result like: > > <doc> > <!-- stuff --> > <perslist> > <officers> > <person>Ms Foo</person> > <person>Mr Bar</person> > </officers> > <person>Mss Toto</person> > <person>Dr Tata</person> > </perslist> > <!-- other stuff --> > </doc> > How about this? It produces what you said you want, e xcept for formatting details. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <perslist> <officers> <xsl:for-each select='/doc/person[@er="officer"]'> <person><xsl:value-of select='.'/></person> </xsl:for-each> </officers> <xsl:for-each select='/doc/person[not(@er="officer")]'> <person><xsl:value-of select='.'/></person> </xsl:for-each> </perslist> </xsl:template> </xsl:stylesheet> Cheers, Tom P
|
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








