[
Lists Home |
Date Index |
Thread Index
]
- From: "Thomas B. Passin" <tpassin@home.com>
- To: xml-dev@lists.xml.org
- Date: Fri, 15 Dec 2000 08:42:21 -0500
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
|