From: GArlington on 8 Jul 2008 07:07 On Jul 7, 8:41 pm, Joachim <Joac...(a)discussions.microsoft.com> wrote: > I have a XML file with belonging XSL file. Opening the XML file in IE7 works > just fine. But when using the following code I get the error message: > > "Attribute and namespace nodes cannot be added to the parent element after a > text, comment, pi, or sub-element node has already been added." > > XPathNavigator nav = > xml_document.DocumentElement.CreateNavigator(); > XslCompiledTransform xslt = new XslCompiledTransform(); > xslt.Load(xsl_document_location); > xslt.Transform(nav, null, output_stream); > > My XSL code contains some portions of code like this: > > <xsl:element name="img"> > <xsl:attribute name="class">drawing</xsl:attribute> > <xsl:attribute name="width">100%</xsl:attribute> > <xsl:attribute name="src"> > <xsl:value-of select="Folder" /> > <xsl:text disable-output-escaping="yes">/</xsl:text> > <xsl:value-of select="Filename" /> > </xsl:attribute> > </xsl:element> > > A thread I found > (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=627581&SiteID=1) says > that attribute nodes should be created before element nodes. This is find > very strange since the attribute is a part of the element, not vice versa. > Anyone? AFAIR you need to define complex types BEFORE you use them. In your case <xsl:attribute name="src"> IS a complex type... This may be the cause of the error...
From: Marc Gravell on 8 Jul 2008 07:56 xsl:attribute is defined by xslt itself; so as long as xsl points to the right namespace this shouldn't be an issue. Marc
From: Pavel Minaev on 10 Jul 2008 08:05 On Jul 8, 10:26 am, Marc Gravell <marc.grav...(a)gmail.com> wrote: > attributes definitely follow elements in xslt They do not. I've quoted the XSLT specification which says, in plain English, that it is not allowed to add any attributes after a child element has been added. An XSLT processor may still allow it as an extension, but it is not standard XSLT, and it would seem that XslCompiledTransform follows the spec here. It would be pretty tricky to write an attribute after a child element to an XmlWriter, anyway...
From: Pavel Minaev on 10 Jul 2008 08:06 On Jul 8, 3:07 pm, GArlington <garling...(a)tiscali.co.uk> wrote: > AFAIR you need to define complex types BEFORE you use them. > In your case <xsl:attribute name="src"> IS a complex type... > This may be the cause of the error... <xsl:attribute> is not a type at all, and @src attribute should have type xs:anyURI, which is not complex (but it is irrelevant here anyway, since no type is being referenced in the XSLT snippet posted).
From: Marc Gravell on 10 Jul 2008 08:31 Yes, but if you consider the context of the OP's remark: <q> A thread I found [snip]says that attribute nodes should be created before element nodes. This is find very strange since the attribute is a part of the element, not vice versa. Anyone? </q> It seems clear to me that the OP is referring to the *containing* element. And the attribute declarations definitely follow the *containing* element declaration. If my phrasing was unfortunate then sorry for confusion; but I was referring to the OPs remark. Yes, attribute declarations preceed other *child* content nodes, but that isn't what I was referring to. Either way, it is *still* simpler to use the inline syntax <img src="{$foo}"/> ;-p Marc
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: BitBlt is faster Next: Does calling MemoryStream.Dispose() do anything ? |