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 xsl:for的逻辑不清楚_Xml_Xslt_Xslt 1.0 - Fatal编程技术网

Xml xsl:for的逻辑不清楚

Xml xsl:for的逻辑不清楚,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,输入:- <b> <cac:OrderLine> <cac:LineItem> <cbc:ID>1</cbc:ID> <cbc:Quantity unitCode="KGM">100</cbc:Quantity> <cbc:TotalTaxAmount currencyID="GBP">1

输入:-

<b>
<cac:OrderLine>

        <cac:LineItem>
            <cbc:ID>1</cbc:ID>
                <cbc:Quantity unitCode="KGM">100</cbc:Quantity>
                    <cbc:TotalTaxAmount currencyID="GBP">17.50</cbc:TotalTaxAmount>
            <cac:Price>
                <cbc:PriceAmount currencyID="GBP">100.00</cbc:PriceAmount>
                 <cbc:BaseQuantity unitCode="KGM">1</cbc:BaseQuantity>
            </cac:Price>
            </cac:LineItem>
                 </cac:OrderLine>
<cac:OrderLine>
    <cac:LineItem>
            <cbc:ID>5</cbc:ID>
                <cbc:Quantity unitCode="KGM">300</cbc:Quantity>
                    <cbc:TotalTaxAmount currencyID="GBP">100.50</cbc:TotalTaxAmount>
            <cac:Price>
                <cbc:PriceAmount currencyID="GBP">2000.00</cbc:PriceAmount>
                 <cbc:BaseQuantity unitCode="KGM">52</cbc:BaseQuantity>
            </cac:Price>
            </cac:LineItem>
                 </cac:OrderLine>

1.
100
17.50
100
1.
5.
300
100.50
2000
52

实际上这是输入结构,如果我们像这样应用循环

<xsl:for-each select="b/OrderLine/LineItem">

它应该只选择第一个行项目,但选择输入中存在的所有行项目?有人能在这里解释一下xsl:for-each的功能吗

因为循环应该应用于upto Order本身,但是上面编写的代码是如何挑选输入文件中存在的所有行项目的“查找所有
b
节点,然后在中查找所有
OrderLine
节点,然后在中查找所有
LineItem
节点。是的,这是预期的功能

旁注:您应该为每个使用模板,而不是
。(ForEach是开发人员从其他语言使用XSLT时使用的工具。)

如果只需要每个
订单行中的第一个
行项目
节点
,则快速修改如下:

<xsl:for-each select="b/OrderLine/LineItem[1]">


。使用

<xsl:template match="b/OrderLine/LineItem[1]">
    ....
</xsl:template>

....

顾名思义,对于每个
,它都会处理与
选择
表达式匹配的每个项。您可以为每个项使用2个xsl:

<xsl:for-each select="b/OrderLine">
    <!-- loop for each OrderLine -->
    <xsl:for-each select="LineItem">
    <!-- loop for each LineItem -->
    </xsl:for-each>
</xsl:for-each>

针对您的问题:

1) 你没有提到在哪里

<b>

即将结束

2) 如果您的xpath选择了所有节点,那么它肯定是文档的根节点

3)

名称本身证明逻辑将应用于xpath所指向的“每个”元素