I'm using XslTransform to apply a transform to an XML document, however I
get validation problems when parsing the resulting XML document due to
invalid whitespace. I'm passing in an XPathNavigator for the input to the
Transform method and specifying a Stream for the output.
Here is an example of a transform and a document (it's the IconStyle
sections that are causing problems):
<?xml version="1.0" encoding="UTF-16"?>
<!-- Copyright i2 Ltd 2002-2003. All rights reserved. -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes" encoding="UTF-16"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Calls">
<Doc>
<ItemCollection>
<xsl:for-each select="Call">
<xsl:element name="Item">
<xsl:attribute name="Label"><xsl:value-of
select="@from"/></xsl:attribute>
<Icon>
<xsl:element name="IconStyle">
<xsl:attribute name="Type">Telephone</xsl:attribute>
</xsl:element>
</Icon>
</xsl:element>
<xsl:element name="Item">
<xsl:attribute name="Label"><xsl:value-of
select="@to"/></xsl:attribute>
<Icon>
<xsl:element name="IconStyle">
<xsl:attribute name="Type">Telephone</xsl:attribute>
</xsl:element>
</Icon>
</xsl:element>
</xsl:for-each>
</ItemCollection>
</Doc>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-16"?>
<Calls>
<Call from="01339 842744" to="01226 441998" duration="2"/>
<Call from="01339 842744" to="01226 441998" duration="3"/>
<Call from="01663 254564" to="01882 123456" duration="3"/>
<Call from="01226 441998" to="01339 842744" duration="12"/>
<Call from="01882 123456" to="01663 868943" duration="7"/>
</Calls>
I was previously using MSXML4, which would produce something as follows:
<IconStyle Type="Telephone"/>
Now I understand that the above is considered to be identical to the
following:
<IconStyle Type="Telephone"></IconStyle>
Unfortunately when running the same transform on the same document using
XslTransform, the result is as follows:
<IconStyle Type="Telephone">
</IconStyle>
AFAICT this is not equivalent to the MSXML4 result. If I turn off indenting
in the transform then the transformed XML is valid but has no formatting
whatsoever. Am I missing something about using XslTransform or was the
previous behaviour of MSXML4 wrong?
--
Kevin Westhead