2012-12-06 55 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

相關問題