使用以下兄弟姐妹 [英] use of following-sibling

查看:96
本文介绍了使用以下兄弟姐妹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的简单文件:


<接受>

< XXXX />

< ; Token image =" From" />

< Date value =" 2007-01-01" />

< Token image ="至/>

< Date value =" 2007-01-01" />

< / Accept>


我想在to令牌后面获取日期元素。 (来自和

都是可选的,所以它不能只是相对位置)


我使用以下查询:" child :: Token [ fn:upper-

case(@image)=''TO''] / follow-sibling :: *"

但我的问题是它是'总是给我回复令牌和日期

元素。我本来希望只得到日期元素。


现在我改为:child :: Token [fn:upper-case(@image)=''FROM ''] /

follow-sibling :: * [2]"这很有效,但我觉得我很想念

这里的东西。


请帮忙。

谢谢

Alain

I have a simple document like this:

<Accept>
<XXXX/>
<Token image="From"/>
<Date value="2007-01-01"/>
<Token image="To"/>
<Date value="2007-01-01"/>
</Accept>

where i want to get the date element following the to token. (from and
to are both optional, so it cannot be only position relative)

I am using the following query: "child::Token[fn:upper-
case(@image)=''TO'']/following-sibling::*"
but my problem is that it''s always returning me the token and the date
element. I would have expected to only get the date element.

For now i changed it to: "child::Token[fn:upper-case(@image)=''FROM'']/
following-sibling::*[2]" and that works, but I feel like I am missing
something here.

Please help.
Thanks
Alain

推荐答案

我使用以下查询:" child :: Token [fn:upper-
I am using the following query: "child::Token[fn:upper-

case(@image)=''TO''] / follow-sibling :: *"

但我的问题是它'总是给我回复令牌和日期

元素。我本来希望只获得日期元素。
case(@image)=''TO'']/following-sibling::*"
but my problem is that it''s always returning me the token and the date
element. I would have expected to only get the date element.



以下兄弟轴返回以下所有兄弟姐妹,除非你指定你想要的兄弟姐妹 - 按姓名,按位置或按其他一些

标准。


如果您希望单个日期最接近FROM令牌,请尝试

" child: :Token [fn:upper-case(@image)=''FROM''] / follow-sibling :: Date [1]"


XSLT是一种编程语言。如果你对你的要求很模糊,那么你会得到模糊的结果。


-

() ASCII功能区活动| Joe Kesselman

/ \标记HTML电子邮件! |系统architexture和动态诗歌

The following sibling axis returns all following siblings, unless you
specify which one you want -- by name, by position, or by some other
criterion.

If you want the single Date most closely following the FROM Token, try
"child::Token[fn:upper-case(@image)=''FROM'']/following-sibling::Date[1]"

XSLT is a programming language. If you''re fuzzy about what you ask for,
you get back fuzzy results.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry


在文章< Wq ************************* *****@comcast.com>,

Joe Kesselman< ke ************ @ comcast.netwrote:
In article <Wq******************************@comcast.com>,
Joe Kesselman <ke************@comcast.netwrote:

>我使用以下查询:" child :: Token [fn:upper-
case(@image)=''TO'' ] / follow-sibling :: *"
但我的问题是它总是返回我的令牌和日期
元素。我本来希望只获得日期元素。
>I am using the following query: "child::Token[fn:upper-
case(@image)=''TO'']/following-sibling::*"
but my problem is that it''s always returning me the token and the date
element. I would have expected to only get the date element.


>以下兄弟轴返回以下所有兄弟姐妹,除非你指定你想要的那个 - 按名称,按位置,或通过其他一些
标准。
>The following sibling axis returns all following siblings, unless you
specify which one you want -- by name, by position, or by some other
criterion.



是的,但考虑到OP的例子:


<接受>

< XXXX />

< Token image =" From" />

< Date value =" 2007-01-01" /> ;

< Token image =" To" />

< Date value =" 2007-01-01" />

< /接受>


令牌元素@ image = To只有一个后续兄弟元素

元素。因此,他的表达应该只返回最后的日期

元素。


- Richard

-

在一些字母表中应考虑需要多达32个字符

- X3.4,1963。

Yes, but given the OP''s example:

<Accept>
<XXXX/>
<Token image="From"/>
<Date value="2007-01-01"/>
<Token image="To"/>
<Date value="2007-01-01"/>
</Accept>

the Token element with @image=To only has one following-sibling
element. His expression should therefore return only the final Date
element.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.


Richard Tobin写道:
Richard Tobin wrote:

是的,但考虑到OP''例如:
Yes, but given the OP''s example:



你是对的,我正在匆忙阅读,以及纠缠他的两个

草绘的soltuions。 (对不起;在房子上谈判,有点

分心。)Lemme重新检查...

You''re right, I was reading in a hurry, as well entangling his two
sketched soltuions. (Sorry; negotiating on a house and somewhat
distracted.) Lemme recheck...


< Accept>

< XXXX />

< Token image =" From" />

< Date value =" 2007-01-01" />

< Token image =" To" />

< Date value =" 2007-01-01" />

< /接受>
<Accept>
<XXXX/>
<Token image="From"/>
<Date value="2007-01-01"/>
<Token image="To"/>
<Date value="2007-01-01"/>
</Accept>


>" child :: Token [fn:upper-case(@image)=''TO''] / follow-sibling: :*"
>"child::Token[fn:upper- case(@image)=''TO'']/following-sibling::*"



在这个特定的例子中,它应该返回第二个Date。如果

是TO之后的任何其他元素。令牌,他们也将返回
。鉴于< XXXX />,我认为这是一个简化的例子,因此我认为他最好限制它。


child :: Token [fn:upper-case(@image)=''TO''] / follow-sibling :: * [1]"

确实应该工作,返回下面的第一个兄弟元素。

(虽然我仍然建议明确使用child :: Token [fn:upper-

case(@image)= ''to''] / follow-sibling :: Date [1]")


他的解决方法,child :: Token [fn:upper-case(@image) =''FROM''] /

follow-sibling :: * [2]",SHOULDN''T work - 应返回

" TO"令牌,而不是日期,假设输入的描述是正确的
。他声称它确实有效,这表明他正在使用的XPath

实现被破坏或者输入实际上并没有显示出来。
。 />

我可能仍然半睡着,分心和语无伦次;道歉如果

所以...但是这里有些东西我不见了。

(这就是为什么相关数据通常应分组为

父子,或更高级别的包装,或作为单个

元素的属性,而不是指望订单。)


-

()ASCII Ribbon Campaign | Joe Kesselman

/ \标记HTML电子邮件! |系统架构和动态诗歌

In this particular example, that should return the second Date. If there
are any other elements following the "TO" token, they will also be
returned. Given the <XXXX/>, I presume this is a simplified example, and
thus I presume he''d be better off limiting it.

"child::Token[fn:upper- case(@image)=''TO'']/following-sibling::*[1]"
indeed ought to work, to return the first following sibling element.
(though I''d still suggest explicitly using "child::Token[fn:upper-
case(@image)=''TO'']/following-sibling::Date[1]")

His workaround, "child::Token[fn:upper-case(@image)=''FROM'']/
following-sibling::*[2]", SHOULDN''T work -- that should be returning the
"TO" token, not the date, assuming the description of the input is
correct. He claims it does work, which suggests that either the XPath
implementation he''s using is broken or that the input isn''t actually as
shown.

I may still be half-asleep and distracted and incoherent; apologies if
so... but there''s something here I''m missing.
(This is why associated data should generally be grouped as
parent-child, or in a higher-level wrapper, or as attributes on a single
element, rather than counting on the order.)

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry


这篇关于使用以下兄弟姐妹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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