2012-12-06 58 views
1

我确定这应该非常简单 - 但是我遇到了上下文问题!确定以下兄弟节点是否包含具有相同值的节点

例XML:

<test> 
<HtlSeg> 
    <SegNum>1</SegNum> 
    <StartDt>20130624</StartDt> 
    <NumNights>2</NumNights> 
    <Conf>28618</Conf> 
</HtlSeg> 
<CommentInfo> 
    <CommentNum>1</CommentNum> 
    <SegMatch>28618</SegMatch> 
    <Comment>THIS IS A TEST</Comment> 
</CommentInfo> 
<CommentInfo> 
    <CommentNum>2</CommentNum> 
    <SegMatch>28618</SegMatch> 
    <Comment>HOTEL BOOKED</Comment> 
</CommentInfo> 
<CommentInfo> 
    <CommentNum>3</CommentNum> 
    <SegMatch>28618</SegMatch> 
    <Comment>NON REFUNDABLE</Comment> 
</CommentInfo> 
<CommentInfo> 
    <CommentNum>4</CommentNum> 
    <SegMatch>1459</SegMatch> 
    <Comment>CAR BOOKING</Comment> 
</CommentInfo> 
<CommentInfo> 
    <CommentNum>5</CommentNum> 
    <SegMatch>1528</SegMatch> 
    <Comment>AIR BOOKING</Comment> 
</CommentInfo> 
<CommentInfo> 
    <CommentNum>6</CommentNum> 
    <SegMatch>1528</SegMatch> 
    <Comment>NON REFUNDABLE</Comment> 
</CommentInfo> 
<CommentInfo> 
    <CommentNum>7</CommentNum> 
    <SegMatch>1528</SegMatch> 
    <Comment>NON SMOKING</Comment> 
</CommentInfo> 

在XSLT我的上下文节点是<HtlSeg>

我试着访问<CommentInfo>节点,其中<SegMatch>节点等于<HotelSeg><Conf>节点。

我尝试了XPath是following-sibling::CommentInfo[SegMatch=Conf]/Comment

但是不返回任何东西。当我在xpath中使用'Conf'时,我想我已经失去了<HotelSeg>的上下文 - 但是我确定这必须可以在一个简单的Xpath中进行,而不必声明变量。

干杯 达伦

回答

2

使用current() method

[SegMatch=current()/Conf] 
+0

阿好,谢谢! current()是一个仅用于XSLT的函数 - 我正在使用XMLSpy和xpath测试器测试我的xpaths - 它不允许您使用xslt函数!非常感谢您的帮助! – DarrenNavitas

相关问题