Lists Home |
Date Index |
> I have the following element in the source XML which I am trying to
> transform to a target XML. I am using
> XslTransform.Transform method in .NET framework with MSXML4.0 parser.
> <sampleElement attrib="someValue" />
> My XSL code looks like this:
> <xsl:element name="newElement">
> <xsl:attribute name="newAttrib">
> <xsl:value-of select="sampleElement/@attrib" />
> Output XML generated is:
> <newElement newAttrib="someValue">
> Eventhough "sampleElement" is an empty element, in the output XML I
> a separate endtag separated by the
> the starttag with spaces.
> I am using the XmlTextWriter to generate the output XML and the above
> problem arises when I set
> XmlTextWriter.Indentation to Formatting.Indented. What could be the
Notice that there really is whitespace in your stylesheet. The processor
has to figure out whether you mean it to be there literally or just for
visual formatting. Xslt has rules for this situation, and the rules say to
eliminate such whitespace-only nodes (unless, in a stylesheet, they appear
in an xsl:text element - there are other rules for whitespace-only nodes in
the source document).
Apparently this processor is not doing the stripping. Perhaps it is a user
option that you can turn off or on. Check the documentation for the .NET.
Also, it would be simpler to write your snippet this way, using a literal
result element and attribute value syntax -
This should get through the proccessor, bug or not, OK because it has no
> Expected output would be:
> <newElement newAttrib="someValue" />
That is what I get with both MSXML4 and Saxon (as expected).
I would suggest 1) using the simplified form I show above, 2) if for some
reason you have to use xsl:element and xsl:attribute (unlikely), see if
there is a transformer option to control the behavior, and lastly, 3),
eliminate extra whitespace like this (the email system may cause this to
<xsl:element name="newElement"><xsl:attribute name="newAttrib"><xsl:value-of