Preserving whitespaces from the XSL stylesheet

God Caly

New Member
I'm trying to convert this XML :- \[code\]<list> <unit> <data1>a</data1> <data2>b</data2> <data3>c</data3> </unit></list>\[/code\]to this :- \[code\]<list> <unit> <category1> <data1>a</data1> <data2>b</data2> </category1> <category2> <data3>c</data3> </category2> </unit></list>\[/code\]using XSL. I'm using the following XSL:- \[code\]<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="some_namespace"><xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()" /> </xsl:copy></xsl:template><xsl:template match="//s:unit" xml:space="preserve"> <xsl:copy> <category1> <xsl:apply-templates select="./s:data1"/> <xsl:apply-templates select="./s:data2"/> </category1> <category2> <xsl:apply-templates select="./s:data3"/> </category2> </xsl:copy></xsl:template></xsl:stylesheet>\[/code\]Now, this preserves the indentation within but completely messes it up w.r.t. list. This is what I get :- \[code\] <list><unit> <category1> <data1>a</data1> <data2>b</data2> </category1> <category2> <data3>c</data3> </category2></unit> </list>\[/code\]What am I missing here?
 
Back
Top