OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: [xml-dev] Problem with XSLT

[ Lists Home | Date Index | Thread Index ]

[Avinash Subramanya]
>      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" />
>              </xsl:attribute>
>         </xsl:element>
>      Output XML generated is:
>      <newElement newAttrib="someValue">
>      </newElement>
>      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
> reason???

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 -

         <newElement newAttrib='{sampleElement/@attrib}'/>

This should get through the proccessor, bug or not, OK because it has no
embedded whitespace.

>      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
wrap) -

<xsl:element name="newElement"><xsl:attribute name="newAttrib"><xsl:value-of
select="sampleElement/@attrib" /></xsl:attribute></xsl:element>


Tom P


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS