当xpath的值不存在时,xsl会抛出异常吗? [英] Can xsl throw an exception when value-of xpath does not exist?

查看:64
本文介绍了当xpath的值不存在时,xsl会抛出异常吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi-


对我来说,xsl的一个令人讨厌的事情是我不知道

如何让xslt抛出某种异常时路径值

不存在。例如,假设我有以下行:

xslt

< xsl:value-of select =" / blah / q" />


和我的xml文档没有节点/ blah / q。输出将

只是将文档的这部分留空。有时候这就是我想要的b $ b,但通常表明存在错误(例如,节点名称中的拼写错误)。 xml

文档中的拼写错误可以被架构或dtd捕获,但xslt

转换中的错误根本无法捕获(据我所知) 。我不是b $ b不正确吗?有没有办法做到这一点?如果没有,我建议添加




哦,我知道*可以*使用额外的编码,如

< xsl:if>但考虑到这个节点必须在xslt文档中输入两次,因此这绝对不是一个可接受的解决方案因此

不能用于测试拼写错误的目的等等


谢谢

-I

Hi-

One frusterating thing for me with xsl is that I don''t know
how to make xslt throw some sort of exception when a value-of path
does not exist. For instance, suppose I have the following line in
xslt

<xsl:value-of select="/blah/q" />

and my xml document does not have a node /blah/q. The output would
just leave this part of the document empty. Sometimes this is what I
would like, but often it is indicative of a mistake (for instance, a
spelling mistake in the node name). Spelling mistakes in the xml
document can be caught by a schema or dtd, but ones in the xslt
transformation can not be caught at all (as far as I know). Am I
incorrect? Is there a way to do this? If not, I would suggest that
it be added.

Oh, and I know it *can* be done by using extra coding like
<xsl:if> but this ceratinly isn''t an acceptable solution considering
that the node has to be typed in twice in the xslt document therefore
not serving the purpose of testing for spelling mistakes, etc.

thanks
-I

推荐答案

8月15日2004 14:12:36 -0700, in********@hotmail.com (inquirydog )

写道:
On 15 Aug 2004 14:12:36 -0700, in********@hotmail.com (inquirydog)
wrote:
哦,我知道*可以*使用额外的编码来完成,例如
< xsl:if>但这绝对不是一个可接受的解决方案
Oh, and I know it *can* be done by using extra coding like
<xsl:if> but this ceratinly isn''t an acceptable solution




将它粘贴在变量中,测试变量,如果不是空的则输出

变量。



Stick it in a variable, test the variable, if not empty then output
the variable.


在****** **@hotmail.com (inquirydog)在留言中写道:< 80 ************************** @发布。谷歌。 com> ...
in********@hotmail.com (inquirydog) wrote in message news:<80**************************@posting.google. com>...
Hi-

对我来说,xsl的一个令人讨厌的事情是我不知道如何让xslt抛出某种东西路径值
不存在时的异常。例如,假设我在
xslt

< xsl:value-of select =" / blah / q"中有以下行: />

我的xml文档没有节点/ blah / q。输出将只留下文档的这一部分为空。
Hi-

One frusterating thing for me with xsl is that I don''t know
how to make xslt throw some sort of exception when a value-of path
does not exist. For instance, suppose I have the following line in
xslt

<xsl:value-of select="/blah/q" />

and my xml document does not have a node /blah/q. The output would
just leave this part of the document empty.




这样做,因为你使用的是价值而不是复制 - of:


< xsl:variable name =" foo">

< xsl:copy-of select =" / blah / q" ; />

< / xsl:variable>

< xsl:choose>

< xsl:when test ="



This will do it, since you''re using value-of and not copy-of:

<xsl:variable name="foo">
<xsl:copy-of select="/blah/q"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="


foo">

< xsl:value-of select ="
foo">
<xsl:value-of select="


这篇关于当xpath的值不存在时,xsl会抛出异常吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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