Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
根据条件,XML中的行数减少_Xml - Fatal编程技术网

根据条件,XML中的行数减少

根据条件,XML中的行数减少,xml,Xml,目前我有以下XML: <Rowsets> <Rowset> <Row> <DrilldownDepth>0</DrilldownDepth> <ScheduleWeek>---</ScheduleWeek> <ABC>---</ABC> <PQR>1500&l

目前我有以下XML:

<Rowsets>
    <Rowset>
        <Row>
            <DrilldownDepth>0</DrilldownDepth>
            <ScheduleWeek>---</ScheduleWeek>
            <ABC>---</ABC>
            <PQR>1500</PQR>
            <XYZ>15000</XYZ>
            <Quant>285</Quant>
        </Row>
        <Row>
            <DrilldownDepth>1</DrilldownDepth>
            <ScheduleWeek>12</ScheduleWeek>
            <ABC>---</ABC>
            <PQR>1500</PQR>
            <XYZ>15000</XYZ>
            <Quant>285</Quant>
        </Row>
        <Row>
            <DrilldownDepth>2</DrilldownDepth>
            <ScheduleWeek>12</ScheduleWeek>
            <ABC>SUPER</ABC>
            <PQR>100</PQR>
            <XYZ>200</XYZ>
            <Quant>300</Quant>
        </Row>
        <Row>
            <DrilldownDepth>2</DrilldownDepth>
            <ScheduleWeek>12</ScheduleWeek>
            <ABC>Duper</ABC>
            <PQR>100</PQR>
            <XYZ>200</XYZ>
            <Quant>300</Quant>
        </Row>
        <Row>
            <DrilldownDepth>2</DrilldownDepth>
            <ScheduleWeek>12</ScheduleWeek>
            <ABC>Fun</ABC>
            <PQR>100</PQR>
            <XYZ>200</XYZ>
            <Quant>300</Quant>
        </Row>
        <Row>
            <DrilldownDepth>2</DrilldownDepth>
            <ScheduleWeek>7</ScheduleWeek>
            <ABC>SUPER</ABC>
            <PQR>100</PQR>
            <XYZ>200</XYZ>
            <Quant>300</Quant>
        </Row>
        <Row>
            <DrilldownDepth>2</DrilldownDepth>
            <ScheduleWeek>7</ScheduleWeek>
            <ABC>Duper</ABC>
            <PQR>100</PQR>
            <XYZ>200</XYZ>
            <Quant>300</Quant>
        </Row>
        <Row>
            <DrilldownDepth>2</DrilldownDepth>
            <ScheduleWeek>8</ScheduleWeek>
            <ABC>SUPER</ABC>
            <PQR>100</PQR>
            <XYZ>200</XYZ>
            <Quant>300</Quant>
        </Row>
    </Rowset>
</Rowsets>

0
---
---
1500
15000
285
1.
12
---
1500
15000
285
2.
12
超级的
100
200
300
2.
12
骗子
100
200
300
2.
12
乐趣
100
200
300
2.
7.
超级的
100
200
300
2.
7.
骗子
100
200
300
2.
8.
超级的
100
200
300
现在我只需要那些
,其中
2
12
。我可以使用repeater/loop实现它,但我需要使用Xpath或XSLT实现它。因此,在这件事上给予任何帮助都将不胜感激


Sots

以下XPath语句使用筛选器选择包含满足指定条件的子元素的行元素:

/Rowsets/Rowset/Row[DrilldownDepth=2 and ScheduleWeek=12]
对XSLT中应用的值使用变量:

<xsl:variable name="depth">2</xsl:variable>
<xsl:variable name="week">12</xsl:variable>
<xsl:apply-templates select="/Rowsets/Rowset/Row[DrilldownDepth=$depth and ScheduleWeek=$week]"/>
2
12

and运算符的替代方法是使用第二个谓词。哪一个更好取决于个人风格,但如果你仔细查看大量答案,你会发现多谓词方法是流行的选择

看起来像这样

 /Rowsets/Rowset/Row[DrilldownDepth='2'][ScheduleWeek='12']

注意:这同样适用于文字数字周围带引号或不带引号的情况。如果没有,可能会更具可读性。使用可能会稍微更有效率。这也是一种风格选择。

谢谢汉森。但是,在“2”和“12”通过变量传递的情况下,使用XSLT或XQUERY可以实现这一点吗?是的。将变量替换为值当前我正在尝试XSLT:2 12不工作您正在使用谓词过滤器迭代
行集
元素,选择包含
元素的
元素,这些元素包含
深入钻取
secscheduleweek
,然后复制
行集
元素(其中包含所有这些
元素)。如果只需要符合条件的
元素,则需要选择它们,而不是
行集
。谢谢Sean。但是,在“2”和“12”通过变量传递的情况下,可以使用XSLT或XQUERY实现这一点吗?