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>等于<Conf>.<HotelSeg>

我试过的xpath是following-sibling::CommentInfo[SegMatch=Conf]/Comment

但是不返回任何东西。我认为在 xpath 中使用“Conf”时我已经失去了上下文<HotelSeg>- 但我确信这在简单的 Xpath 中必须是可能的,而无需声明变量?

干杯达伦

4

1 回答 1

2

使用current()方法

[SegMatch=current()/Conf]
于 2012-12-06T18:23:14.873 回答