XSL转换 [英] XSL transforms

查看:80
本文介绍了XSL转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个属于XSL文件的XML文件。在IE7中打开XML文件工作

就好了。但是当使用以下代码时,我收到错误消息:


"

文本后,属性和命名空间节点无法添加到父元素,注释已添加,pi或子元素节点。


XPathNavigator nav =

xml_document.DocumentElement.CreateNavigator();

XslCompiledTransform xslt = new XslCompiledTransform();

xslt.Load(xsl_document_location);

xslt.Transform(nav,null,output_stream);


我的XSL代码包含以下代码的一些部分:


< xsl:element name =" img">

< xsl:attribute name =" class"> drawing< / xsl:attribute>

< xsl:attribute name =" width"> 100%< / xsl:属性>

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


我发现的一个帖子

http: //forums.microsoft.com/MSDN/Sho...27581&SiteID=1 )说

应该在元素节点之前创建属性节点。这是很奇怪的,因为属性是元素的一部分,反之亦然。

任何人?

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/Sho...27581&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?

推荐答案

Joachim kirjoitti:
Joachim kirjoitti:

我有一个属于XSL文件的XML文件。在IE7中打开XML文件工作

就好了。但是当使用以下代码时,我收到错误消息:


"

文本后,属性和命名空间节点无法添加到父元素,注释已添加,pi或子元素节点。


XPathNavigator nav =

xml_document.DocumentElement.CreateNavigator();

XslCompiledTransform xslt = new XslCompiledTransform();

xslt.Load(xsl_document_location);

xslt.Transform(nav,null,output_stream);


我的XSL代码包含以下代码的一些部分:


< xsl:element name =" img">

< xsl:attribute name =" class"> drawing< / xsl:attribute>

< xsl:attribute name =" width"> 100%< / xsl:属性>

< xsl:属性名称=" src">

< xsl:value-of select =" Folder" ; />

< xsl:text disable-output-escaping =" yes"> /< / xsl:text>

< xsl:value- of select =" Filename" />

< / xsl:attribute>

< / xsl:element>
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>



xsl :attribute创建新属性。 xsl:text将文本附加到

元素。所以xsl:text将< imgelement和

添加到src属性的末尾会导致错误消息。


我会尝试


< xsl:variable name =" slash">< xsl:text

disable-output-escaping =" yes"> / < / xsl:text>< / xsl:variable>

< 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:value-of select ="

xsl:attribute creates new attribute. xsl:text appends text to the
element. So xsl:text adds / to the <imgelement, and
the end of the src attribute causes the error message.

I''d try

<xsl:variable name="slash"><xsl:text
disable-output-escaping="yes">/</xsl:text></xsl:variable>
<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:value-of select="


slash" />

< xsl:value-of select =" Filename" />

< / xsl:attribute>

< / xsl:element>


代替。
slash" />
<xsl:value-of select="Filename" />
</xsl:attribute>
</xsl:element>

instead.

我发现的一个帖子

http://forums.microsoft.com/MSDN/Sho...27581&SiteID=1 )说

应该在元素节点之前创建属性节点。这是非常奇怪的,因为属性是元素的一部分,反之亦然。
A thread I found
(http://forums.microsoft.com/MSDN/Sho...27581&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.



我想这意味着,应该在添加属性

之后添加子元素。

I guess it means, that subelements should be added after the attributes
are added.


任何人?
Anyone?



-

Arto Viitanen

--
Arto Viitanen


7月7日,11:41 * pm,Joachim< Joac ... @ discussion.microsoft.comwrote:
On Jul 7, 11:41*pm, Joachim <Joac...@discussions.microsoft.comwrote:

我有一个属于XSL文件的XML文件。在IE7中打开XML文件工作

就好了。但是当使用以下代码时,我收到错误消息:


"

文本后,属性和命名空间节点无法添加到父元素,注释已添加,pi或子元素节点。


* * * * * * XPathNavigator nav =

xml_document.DocumentElement.CreateNavigator( );

* * * * * * XslCompiledTransform xslt = new XslCompiledTransform();

* * * * * * xslt.Load(xsl_document_location);

* * * * * * xslt.Transform(nav,null,output_stream);


我的XSL代码包含一些代码部分:

* * * *< 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>


我发现的一个帖子

http://forums.microsoft.com/MSDN/Sho...27581&SiteID=1 )说

应该在元素之前创建属性节点节点。这是发现

非常奇怪,因为属性是元素的一部分,反之亦然..
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/Sho...27581&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..



实际上,这意味着什么是必须在该元素的子元素节点之前创建给定元素的属性节点

。您发布的

特定代码片段没有这个问题,

但显然,其他一些代码确实如此。引用XSLT W3C

建议书( http://www.w3.org/TR/xslt#creating-attributes):


"以下是所有错误:


- 在将子项添加到元素后为元素添加属性

it;实现可能会发出错误信号或忽略

属性。


IE XSLT实现在这方面似乎很松懈,可能是

,因为它适用于可变DOM,而不是仅限前向编写者,

因此限制在那里没有那么多意义。

Actually, what this means is that attribute nodes for a given element
must be created before the child element nodes for that element. The
particular piece of code that you''ve posted doesn''t have this problem,
but, apparently, some other one does. To quote the XSLT W3C
Recommendation (http://www.w3.org/TR/xslt#creating-attributes):

"The following are all errors:

- Adding an attribute to an element after children have been added to
it; implementations may either signal the error or ignore the
attribute."

IE XSLT implementation seems to be lax in that regard, probably
because it works with mutable DOM rather than forward-only writers,
and so the restriction doesn''t make as much sense there.


这篇关于XSL转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆