XML for-each无法正常工作

时间:2016-05-10 09:25:54

标签: xml xslt

作为XML编程的初学者,我偶然发现了一个小问题,试图让for-each工作。我有其他类似的代码,它工作正常,所以从那里借了一些代码并改变了几行(听起来很简单) - 然而,当我尝试执行代码时,我只得到第一个子节点出现,for-每个人似乎都没有传给第二个孩子。

由于

输入XML:

<?xml version="1.0" encoding="Windows-1252"?>
<SalesOrders>
  <Order>
    <OrderHeader>
      <Customer>000008</Customer>
      <SalesOrder>000809</SalesOrder>
    </OrderHeader>
    <OrderDetails>
      <StockLine>
        <SalesOrderLine>0001</SalesOrderLine>
        <StockCode>LOT100</StockCode>
        <Warehouse>FG</Warehouse>
        <Quantity>3.000</Quantity>
        <Lot>500</Lot>
      </StockLine>
      <Stockline>
        <SalesOrderLine>0002</SalesOrderLine>
        <StockCode>LOT101</StockCode>
        <Warehouse>FG</Warehouse>
        <Quantity>4.000</Quantity>
        <Lot>501</Lot>
      </Stockline>
    </OrderDetails>
  </Order>
</SalesOrders>

XSL翻译;

<?xml version="1.0" encoding="windows-1252"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" omit-xml-declaration="yes" />
  <xsl:template match="/">
    <PostSorBackOrderRelease>
      <xsl:for-each select="//OrderDetails/StockLine">
        <Item>
          <Customer>
            <xsl:value-of select="../../OrderHeader/Customer" />
          </Customer>
          <SalesOrder>
            <xsl:value-of select="../../OrderHeader/SalesOrder" />
          </SalesOrder>
          <StockCode>
            <xsl:value-of select="StockCode" />
          </StockCode>
          <Warehouse>
            <xsl:value-of select="Warehouse" />
          </Warehouse>
          <Quantity>
            <xsl:value-of select="Quantity" />
          </Quantity>
          <ActualShipQty>
          </ActualShipQty>
          <UnitOfMeasure />
          <Units />
          <Pieces />
          <ReleaseFromMultipleLines>N</ReleaseFromMultipleLines>
          <SalesOrderLine>
            <xsl:value-of select="SalesOrderLine" />
          </SalesOrderLine>
          <CompleteLine>N</CompleteLine>
          <AdjustOrderQuantity>N</AdjustOrderQuantity>
          <OrderStatus>3</OrderStatus>
          <ReleaseFromShip>N</ReleaseFromShip>
          <ZeroShipQuantity>N</ZeroShipQuantity>
          <AllocateSerialNumbers>N</AllocateSerialNumbers>
          <eSignature>
          </eSignature>
        </Item>
      </xsl:for-each>
    </PostSorBackOrderRelease>
  </xsl:template>
</xsl:stylesheet>

只获得;

的第一个行节点
<PostSorBackOrderRelease>
  <Item>
    <Customer>000008</Customer>
    <SalesOrder>000809</SalesOrder>
    <StockCode>LOT100</StockCode>
    <Warehouse>FG</Warehouse>
    <Quantity>3.000</Quantity>
    <ActualShipQty />
    <UnitOfMeasure />
    <Units />
    <Pieces />
    <ReleaseFromMultipleLines>N</ReleaseFromMultipleLines>
    <SalesOrderLine>0001</SalesOrderLine>
    <CompleteLine>N</CompleteLine>
    <AdjustOrderQuantity>N</AdjustOrderQuantity>
    <OrderStatus>3</OrderStatus>
    <ReleaseFromShip>N</ReleaseFromShip>
    <ZeroShipQuantity>N</ZeroShipQuantity>
    <AllocateSerialNumbers>N</AllocateSerialNumbers>
    <eSignature />
  </Item>
</PostSorBackOrderRelease>

1 个答案:

答案 0 :(得分:1)

XML区分大小写:

<xsl:for-each select="//OrderDetails/StockLine">

选择Stockline小写l