XSL文档()函数错误 [英] XSL Error with document() function

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

问题描述

有人可以解释一下为什么会发生这种情况吗?

预期输出为3,但是第7行取消注释会使输出为0.

为什么???


VB.NET代码:**注意注释行,这是罪魁祸首**

Dim xsl As New System.Xml.Xsl.XslTransform()

Dim xw As New System.IO.StringWriter()

Dim xmldoc As New System.Xml.XmlDocument()

Dim xsldoc As New System.Xml .XmlDocument()

xmldoc.Load(" test.xml")

xsldoc.Load(" test.xsl")

''xsldoc.LoadXml(xsldoc.OuterXml)

xsl.Load(xsldoc.CreateNavigator)

xsl.Transform(xmldoc.CreateNavigator,Nothing,xw)

Console.Write(xw.ToString)

XML输入:(test.xml)

< xml>

< node1 val =" hello world" />

< / xml>


XSL输入:(test.xsl)

< xsl:stylesheet version =" 1.0"

xmlns:xsl =" http://www.w3.org/1999/XSL/Transform">

< xsl: template match =" /">

< xsl:value-of select =" count(document('''')// *)" />

< / xsl:template>

< / xsl:stylesheet>


请解释为什么会发生这种情况,我不想在我的

计划中使用任何文件I / O!

谢谢。


--scott

Can someone please explain why this happens?
The expected output is 3, but uncommenting line 7 makes the output 0.
Why ???

VB.NET code: ** note the commented line, this is the culprit **
Dim xsl As New System.Xml.Xsl.XslTransform()
Dim xw As New System.IO.StringWriter()
Dim xmldoc As New System.Xml.XmlDocument()
Dim xsldoc As New System.Xml.XmlDocument()
xmldoc.Load("test.xml")
xsldoc.Load("test.xsl")
''xsldoc.LoadXml(xsldoc.OuterXml)
xsl.Load(xsldoc.CreateNavigator)
xsl.Transform(xmldoc.CreateNavigator, Nothing, xw)
Console.Write(xw.ToString)
XML input: (test.xml)
<xml>
<node1 val="hello world" />
</xml>

XSL input: (test.xsl)
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:value-of select="count(document('''')//*)" />
</xsl:template>
</xsl:stylesheet>

Please explain why this happens, I do not want to use any file I/O in my
program!
Thanks.

--scott

推荐答案




你想在这里实现什么 - 是否是

源文档,还是样式表?从MSXML参考:


如果将空字符串传递给document()函数,则结果是XSLT文档本身的源XML,

源XML除非给出第二个参数

(并且不为空)。在后一种情况下,文档的URL是第二个元素中包含的节点的基础




所以如果你使用一个空字符串对于文档功能,那么上下文实际上是样式表,而不是源文档。


因此请保留文档(''')函数!


HTH


Nigel


" rox.scott"写道:
Hi

What are you trying to achieve here - is it the count of elements inside the
source document, or the stylesheet? From the MSXML reference:

If an empty string is passed to the document() function, the result is the
source XML of the XSLT document itself, unless the second argument is given
(and is not null). In the latter case, the URL of the document is the base
URL of the node contained in the second element.

So if you use an empty string for the document function, then the context is
actually the stylesheet, not the source document.

So leave the document('''') function out!

HTH

Nigel

"rox.scott" wrote:
有人可以解释为什么会发生这种情况吗?
预期输出为3,但是第7行未注释使输出为0.
为什么??? < VB.NET代码:**注意注释行,这是罪魁祸首**
Dim xsl As New System.Xml.Xsl.XslTransform()
Dim xw As New System.IO.StringWriter()
Dim xmldoc As New System.Xml.XmlDocument()
Dim xsldoc As New System.Xml.XmlDocument()
xmldoc.Load(" test.xml" ;)
xsldoc.Load(" test.xsl")
''xsldoc.LoadXml(xsldoc.OuterXml)
xsl.Load(xsldoc.CreateNavigator)
xsl.Transform (xmldoc.CreateNavigator,Nothing,xw)
Console.Write(xw.ToString)
XML输入:(test.xml)
< xml>
< node1 val = 你好世界 />
< / xml>

XSL输入:(test.xsl)
< xsl:stylesheet version =" 1.0"
xmlns: xsl =" http://www.w3.org/1999/XSL/Transform">
< xsl:template match =" /">
< xsl:value- of select =" count(document(''')// *)" />
< / xsl:template>
< / xsl:stylesheet>

请解释为什么会发生这种情况,我不想使用任何文件I / O在我的
程序中!
谢谢。

- scott
Can someone please explain why this happens?
The expected output is 3, but uncommenting line 7 makes the output 0.
Why ???

VB.NET code: ** note the commented line, this is the culprit **
Dim xsl As New System.Xml.Xsl.XslTransform()
Dim xw As New System.IO.StringWriter()
Dim xmldoc As New System.Xml.XmlDocument()
Dim xsldoc As New System.Xml.XmlDocument()
xmldoc.Load("test.xml")
xsldoc.Load("test.xsl")
''xsldoc.LoadXml(xsldoc.OuterXml)
xsl.Load(xsldoc.CreateNavigator)
xsl.Transform(xmldoc.CreateNavigator, Nothing, xw)
Console.Write(xw.ToString)
XML input: (test.xml)
<xml>
<node1 val="hello world" />
</xml>

XSL input: (test.xsl)
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:value-of select="count(document('''')//*)" />
</xsl:template>
</xsl:stylesheet>

Please explain why this happens, I do not want to use any file I/O in my
program!
Thanks.

--scott



是的,我想要数样式表节点。

这是我现实案例的简化,我实际上并不想要一个节点

计数,但说明了问题。


在任何一种情况下,我都不应该得到0。


--scott


" ;奈杰尔阿姆斯特朗写道:
Yes, I want count of the stylesheet nodes.
This is a simplification of my real-world case, I don''t actually want a node
count, but illustrates the problem.

In either case, I should not get 0 as a result.

--scott

"Nigel Armstrong" wrote:
你好

你想在这里实现什么 - 它是源文档或样式表中元素的数量?从MSXML参考:

如果将空字符串传递给document()函数,则结果是XSLT文档本身的源XML,除非给出第二个参数
(并且不为空)。在后一种情况下,文档的URL是第二个元素中包含的节点的基本URL。

因此,如果对文档函数使用空字符串,那么上下文实际上是样式表,而不是源文档。

请保留文档(''')功能!

HTH


rox.scott写道:
Hi

What are you trying to achieve here - is it the count of elements inside the
source document, or the stylesheet? From the MSXML reference:

If an empty string is passed to the document() function, the result is the
source XML of the XSLT document itself, unless the second argument is given
(and is not null). In the latter case, the URL of the document is the base
URL of the node contained in the second element.

So if you use an empty string for the document function, then the context is
actually the stylesheet, not the source document.

So leave the document('''') function out!

HTH

Nigel

"rox.scott" wrote:
有人可以解释为什么会发生这种情况吗?
预期输出为3,但是第7行未注释使输出为0.
为什么??? < VB.NET代码:**注意注释行,这是罪魁祸首**
Dim xsl As New System.Xml.Xsl.XslTransform()
Dim xw As New System.IO.StringWriter()
Dim xmldoc As New System.Xml.XmlDocument()
Dim xsldoc As New System.Xml.XmlDocument()
xmldoc.Load(" test.xml" ;)
xsldoc.Load(" test.xsl")
''xsldoc.LoadXml(xsldoc.OuterXml)
xsl.Load(xsldoc.CreateNavigator)
xsl.Transform (xmldoc.CreateNavigator,Nothing,xw)
Console.Write(xw.ToString)
XML输入:(test.xml)
< xml>
< node1 val = 你好世界 />
< / xml>

XSL输入:(test.xsl)
< xsl:stylesheet version =" 1.0"
xmlns: xsl =" http://www.w3.org/1999/XSL/Transform">
< xsl:template match =" /">
< xsl:value- of select =" count(document(''')// *)" />
< / xsl:template>
< / xsl:stylesheet>

请解释为什么会发生这种情况,我不想使用任何文件I / O在我的
程序中!
谢谢。

--scott
Can someone please explain why this happens?
The expected output is 3, but uncommenting line 7 makes the output 0.
Why ???

VB.NET code: ** note the commented line, this is the culprit **
Dim xsl As New System.Xml.Xsl.XslTransform()
Dim xw As New System.IO.StringWriter()
Dim xmldoc As New System.Xml.XmlDocument()
Dim xsldoc As New System.Xml.XmlDocument()
xmldoc.Load("test.xml")
xsldoc.Load("test.xsl")
''xsldoc.LoadXml(xsldoc.OuterXml)
xsl.Load(xsldoc.CreateNavigator)
xsl.Transform(xmldoc.CreateNavigator, Nothing, xw)
Console.Write(xw.ToString)
XML input: (test.xml)
<xml>
<node1 val="hello world" />
</xml>

XSL input: (test.xsl)
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:value-of select="count(document('''')//*)" />
</xsl:template>
</xsl:stylesheet>

Please explain why this happens, I do not want to use any file I/O in my
program!
Thanks.

--scott



rox。 scott写道:
rox.scott wrote:
有人可以解释为什么会发生这种情况吗?
预期输出为3,但是第7行取消注释会使输出为0。
Can someone please explain why this happens?
The expected output is 3, but uncommenting line 7 makes the output 0.




当你从一个字符串加载XSLT时,它没有基本URI和relatiev URI

因此无法解决。

不要加载来自字符串的XSLT或者如果你需要,提供基本URI:

xslt.Load(new XmlTextReader(" foo.xsl",new StringReader(strXSL)));


-

Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com


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

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