[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Flattening a tree
Pierre, >However, the first solution is not flat enough and the second one is too >flat ! Erm - it was all supposed to be one solution. Sorry I didn't make that clearer. Using your input: ---- test.xml ---- <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="test.xsl"?> <document> <para> content-1 <List> <Item>content-2</Item> <Item>content-3</Item> </List> content-4 <graphic/> content-5 </para> </document> ---- With the following stylesheet: ---- test.xsl ---- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="*" mode="flatten"> <xsl:choose> <xsl:when test="*"><xsl:apply-templates mode="flatten" /></xsl:when> <xsl:otherwise> <xsl:copy-of select="." /> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="text()" mode="flatten"> <xsl:if test="normalize-space(.) != ''"> <xsl:element name="{name(..)}"> <xsl:value-of select="normalize-space(.)" /> </xsl:element> </xsl:if> </xsl:template> <xsl:template match="document"> <document> <xsl:apply-templates mode="flatten" /> </document> </xsl:template> </xsl:stylesheet> ---- Gives the output: ---- out.xsl ---- <?xml version="1.0"?> <document> <para>content-1</para> <Item>content-2</Item> <Item>content-3</Item> <para>content-4</para> <graphic/> <para>content-5</para> </document> ---- Which is what you said you wanted. This was using SAXON. I hope that works for you now, Jeni Dr Jeni Tennison Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE Telephone 0115 9061301 ? Fax 0115 9061304 ? Email jeni.tennison@xxxxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|