如何在xsl中按条件获取下一个节点?

时间:2013-08-01 11:36:16

标签: xslt xpath xslt-2.0

例如,有一个XML:

<?xml version="1.0" encoding="utf-8"?>
<root>
    <row>
        <Type>1</Type>
        <WeaNr_ArtNr>100027</WeaNr_ArtNr>
        <UID>101114557945</UID>
    </row>
    <row>
        <Type>2</Type>
        <WeaNr_ArtNr>2000311</WeaNr_ArtNr>
        <UID>101114557945</UID>
        <UnitQuantity>10</UnitQuantity>
    </row>
    <row>
        <Type>1</Type>
        <WeaNr_ArtNr>100027</WeaNr_ArtNr>
        <UID>101114557946</UID>
    </row>
<row>
    <Type>2</Type>
    <WeaNr_ArtNr>2000312</WeaNr_ArtNr>
    <UID>101114557946</UID>
    <UnitQuantity>10</UnitQuantity>
</row>
    <row>
        <Type>1</Type>
        <WeaNr_ArtNr>55555</WeaNr_ArtNr>
        <UID>101114558000</UID>
    </row>
    <row>
        <Type>2</Type>
        <WeaNr_ArtNr>200053155555</WeaNr_ArtNr>
        <UID>101114558000</UID>
        <UnitQuantity>1</UnitQuantity>
    </row>
    <row>
        <Type>1</Type>
        <WeaNr_ArtNr>55555</WeaNr_ArtNr>
        <UID>101114558001</UID>
    </row>
    <row>
        <Type>2</Type>
        <WeaNr_ArtNr>200053255555</WeaNr_ArtNr>
        <UID>101114558001</UID>
        <UnitQuantity>1</UnitQuantity>
    </row>
        <row>
        <Type>1</Type>
        <WeaNr_ArtNr>100023</WeaNr_ArtNr>
        <UID>101114557989</UID>
    </row>
    <row>
        <Type>2</Type>
        <WeaNr_ArtNr>2000274</WeaNr_ArtNr>
        <UID>101114557989</UID>
        <UnitQuantity>14</UnitQuantity>
    </row>
    <row>
        <Type>1</Type>
        <WeaNr_ArtNr>100023</WeaNr_ArtNr>
        <UID>101114557990</UID>
    </row>
    <row>
        <Type>2</Type>
        <WeaNr_ArtNr>2000275</WeaNr_ArtNr>
        <UID>101114557990</UID>
        <UnitQuantity>23</UnitQuantity>
    </row>
</root>

通过了解案例WeaNr_ArtNr的{​​{1}}值,我想返回下一个节点

例如,对于Type='1',我想获取这些节点:

WeaNr_ArtNr='100027

因为这些节点在节点<row> <Type>2</Type> <WeaNr_ArtNr>2000311</WeaNr_ArtNr> <UID>101114557945</UID> <UnitQuantity>10</UnitQuantity> </row> <row> <Type>2</Type> <WeaNr_ArtNr>2000312</WeaNr_ArtNr> <UID>101114557946</UID> <UnitQuantity>10</UnitQuantity> </row>

之后

我尝试过这样的事情

WeaNr_ArtNr='100027'

但它不起作用......

1 个答案:

答案 0 :(得分:1)

所以你希望紧跟在WeaNr_ArtNr='100027'的每一行之后的行?那怎么样

/root/row[WeaNr_ArtNr='100027']/following-sibling::row[1]