如何打破每个循环的XSLT

时间:2015-04-29 13:12:41

标签: xslt

这是我的xml结构,我想在运行时解析每个值

 <Header> 'Xml Structure start here'
        <DocNumber>743439</DocNumber> 'Document Number'
           <Order>
          <Order>450</Order> '1 st Order Number'
          <OrderDetails>
             <ItemCode>1232954</ItemCode>
            <Qty> 'Quantity;
              72
            </Qty>
              </OrderDetails>
         <OrderDetails>
             <ItemCode>1232955</ItemCode>
            <Qty>
              72
            </Qty>
             </OrderDetails>
    </Order>
    <Order>
          <Order>451</Order> 'Second order number'
          <OrderDetails>
             <ItemCode>1232954</ItemCode>
            <Qty>
              72
            </Qty>
            </OrderDetails>
         <OrderDetails>
             <ItemCode>1232955</ItemCode>
            <Qty> 'Quantity'
              72
            </Qty>                
          </OrderDetails>
    </Order> 'Xml structure finished here'

我的XSLT:

  <xsl:for-each select="Header/Order">
     <xsl:variable name="OrderNo" select="Order"/>
     <xsl:for-each select="Header/Order[order='450']/OrderDetails"> 'Here Order number i want pass in variable value. how i will do it .it's not fixed next time it's change to 451.'
    </xsl:foreach>
 </xsl:foreach>

为每个循环我想要使用变量传递订单号。我将如何做到。下次改为451时,它不会被修复。我尝试使用变量 <xsl:for-each select="Header/Order[order=<xsl:value-of select="$orderNo"/> ]/OrderDetails">。但它不起作用

1 个答案:

答案 0 :(得分:0)

对于您选择的每个Order元素,您希望迭代子OrderDetail元素。

您不需要为此做任何复杂的事情,因为您的嵌套xsl:for-each可以包含相对于当前节点的xpath表达式。

 <xsl:for-each select="Header/Order">
     Order - <xsl:value-of select="Order" />
     <xsl:for-each select="OrderDetails">
        ItemCode - <xsl:value-of select="ItemCode" />
    </xsl:for-each>
 </xsl:for-each>