为什么我的XSLT无法提取正确的值? “样式表错误”

时间:2019-04-17 13:42:04

标签: xslt mule edi

我正在运行XSLT尝试从入站(看起来像EDI)文件中提取一些信息。我以为我的XSLT看起来正确,但是我遇到了“样式表编译错误”的问题。我缺少明显的东西吗?

示例XML文件-

<?xml version="1.0" encoding="UTF-8"?><sh:StandardBusinessDocument xmlns:sh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader" xmlns:common="urn:SecondGenEDI:common:Japan:1" xmlns:order="urn:SecondGenEDI:order:Japan:1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:SecondGenEDI:common:Japan:1 ../Schemas/SGE_OrderProxy1_3.xsd http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader ../Schemas/sbdh/StandardBusinessDocumentHeader.xsd">
  <sh:StandardBusinessDocumentHeader>
    <sh:HeaderVersion>1.3</sh:HeaderVersion>
    <sh:Sender>
      <sh:Identifier Authority="CODE">0091</sh:Identifier>
    </sh:Sender>
    <sh:Receiver>
      <sh:Identifier Authority="CODE">0001</sh:Identifier>
    </sh:Receiver>
    <sh:DocumentIdentification>
      <sh:Standard>SecondGenEDI</sh:Standard>
      <sh:TypeVersion>1.3</sh:TypeVersion>
      <sh:InstanceIdentifier>0091ORD20181207154032480</sh:InstanceIdentifier>
      <sh:Type>Order</sh:Type>
      <sh:CreationDateAndTime>2018-12-07T15:40:32</sh:CreationDateAndTime>
    </sh:DocumentIdentification>
    <sh:BusinessScope>
      <sh:Scope>
        <sh:Type>Communication</sh:Type>
        <sh:InstanceIdentifier>Test</sh:InstanceIdentifier>
        <sh:Identifier>1</sh:Identifier>
      </sh:Scope>
    </sh:BusinessScope>
  </sh:StandardBusinessDocumentHeader>
  <common:message>
    <entityIdentification>
      <uniqueCreatorIdentification>MSG-0091ORD20181207154032480</uniqueCreatorIdentification>
    </entityIdentification>
    <messageInfo>
    </messageInfo>
    <order:listOfOrders>
      <payer>
        <code>0091</code>
        <gln>0</gln>
      </payer>
      <buyer>
        <code>0091</code>
        <gln>0</gln>
        <name_sbcs>カブシキガイシャ ジーフット</name_sbcs>
      </buyer>
      <order>
        <tradeID>
          <tradeNumber>99999919</tradeNumber>
        </tradeID>
        <parties>
          <shipTo>
            <code>6496</code>
            <gln>0</gln>
            <name_sbcs>ホッカイドウLC</name_sbcs>
          </shipTo>
          <receiver>
            <code>6496</code>
            <gln>0</gln>
            <name_sbcs>ホッカイドウLC</name_sbcs>
          </receiver>
          <transferOfOwnershipLocation>
            <code>6496</code>
            <gln>0</gln>
            <name_sbcs>ホッカイドウLC</name_sbcs>
          </transferOfOwnershipLocation>
          <payee>
            <code>0001</code>
            <gln>0</gln>
            <name_sbcs>テストトリヒキサキ</name_sbcs>
          </payee>
          <seller>
            <code>0001</code>
            <gln>0</gln>
            <name_sbcs>テストトリヒキサキ</name_sbcs>
          </seller>
        </parties>
        <logistics>
          <logisticsLabelInfo>
            <text_sbcs>Pプロパ</text_sbcs>
          </logisticsLabelInfo>
        </logistics>
        <tradeSummary>
          <goodsMajorCategory>
            <majorCategory>0</majorCategory>
            <subMajorCategory>0</subMajorCategory>
          </goodsMajorCategory>
          <dates>
            <orderDate>2018-11-29</orderDate>
            <deliveryDate>2018-12-03</deliveryDate>
            <deliveryDateToReceiver>2018-12-03</deliveryDateToReceiver>
            <transferOfOwnershipDate>2018-12-03</transferOfOwnershipDate>
          </dates>
          <note>
            <text_sbcs>ホンブ01 ホンデン チヤツカシテイビ     ケイカゴ ムコウ           </text_sbcs>
          </note>
        </tradeSummary>
        <lineItem>
          <lineID>
            <lineNumber>01</lineNumber>
          </lineID>
          <goodsMinorCategory>
            <minorCategory>720</minorCategory>
            <detailedCategory>1111</detailedCategory>
          </goodsMinorCategory>
          <itemDeliveryInstruction>
            <deadlineDate>1218</deadlineDate>
          </itemDeliveryInstruction>
          <itemID>
            <makerCode>0</makerCode>
            <gtin>04500000000315</gtin>
            <orderItemCode codeType="999">000001</orderItemCode>
            <name_sbcs>テストショウヒン1</name_sbcs>
          </itemID>
          <itemInfo>
            <itemSpec>
              <spec_sbcs>225250</spec_sbcs>
            </itemSpec>
            <color>
              <colorCode>20</colorCode>
              <description_sbcs>WHITE</description_sbcs>
            </color>
            <size>
              <sizeCode>230</sizeCode>
            </size>
          </itemInfo>
          <amounts>
            <itemNetPrice unitPrice="3999.00">27993</itemNetPrice>
            <itemSellingPrice unitPrice="7490">52430</itemSellingPrice>
          </amounts>
          <quantities>
            <unitMultiple>1</unitMultiple>
            <unitOfMeasure>00</unitOfMeasure>
            <orderQuantity>
              <quantity>7.0</quantity>
              <numOfOrderUnits>7</numOfOrderUnits>
            </orderQuantity>
          </quantities>
        </lineItem>
        <lineItem>
          <lineID>
            <lineNumber>02</lineNumber>
          </lineID>
          <goodsMinorCategory>
            <minorCategory>720</minorCategory>
            <detailedCategory>1112</detailedCategory>
          </goodsMinorCategory>
          <itemDeliveryInstruction>
            <deadlineDate>1218</deadlineDate>
          </itemDeliveryInstruction>
          <itemID>
            <makerCode>0</makerCode>
            <gtin>04500000000322</gtin>
            <orderItemCode codeType="999">000001</orderItemCode>
            <name_sbcs>テストショウヒン1</name_sbcs>
          </itemID>
          <itemInfo>
            <itemSpec>
              <spec_sbcs>225250</spec_sbcs>
            </itemSpec>
            <color>
              <colorCode>20</colorCode>
              <description_sbcs>WHITE</description_sbcs>
            </color>
            <size>
              <sizeCode>235</sizeCode>
            </size>
          </itemInfo>
          <amounts>
            <itemNetPrice unitPrice="3999.00">27993</itemNetPrice>
            <itemSellingPrice unitPrice="7490">52430</itemSellingPrice>
          </amounts>
          <quantities>
            <unitMultiple>1</unitMultiple>
            <unitOfMeasure>00</unitOfMeasure>
            <orderQuantity>
              <quantity>7.0</quantity>
              <numOfOrderUnits>7</numOfOrderUnits>
            </orderQuantity>
          </quantities>
        </lineItem>
        <lineItem>
          <lineID>
            <lineNumber>03</lineNumber>
          </lineID>
          <goodsMinorCategory>
            <minorCategory>720</minorCategory>
            <detailedCategory>1113</detailedCategory>
          </goodsMinorCategory>
          <itemDeliveryInstruction>
            <deadlineDate>1218</deadlineDate>
          </itemDeliveryInstruction>
          <itemID>
            <makerCode>0</makerCode>
            <gtin>04500000000339</gtin>
            <orderItemCode codeType="999">000001</orderItemCode>
            <name_sbcs>テストショウヒン1</name_sbcs>
          </itemID>
          <itemInfo>
            <itemSpec>
              <spec_sbcs>225250</spec_sbcs>
            </itemSpec>
            <color>
              <colorCode>20</colorCode>
              <description_sbcs>WHITE</description_sbcs>
            </color>
            <size>
              <sizeCode>240</sizeCode>
            </size>
          </itemInfo>
          <amounts>
            <itemNetPrice unitPrice="3999.00">27993</itemNetPrice>
            <itemSellingPrice unitPrice="7490">52430</itemSellingPrice>
          </amounts>
          <quantities>
            <unitMultiple>1</unitMultiple>
            <unitOfMeasure>00</unitOfMeasure>
            <orderQuantity>
              <quantity>7.0</quantity>
              <numOfOrderUnits>7</numOfOrderUnits>
            </orderQuantity>
          </quantities>
        </lineItem>
        <lineItem>
          <lineID>
            <lineNumber>04</lineNumber>
          </lineID>
          <goodsMinorCategory>
            <minorCategory>720</minorCategory>
            <detailedCategory>1114</detailedCategory>
          </goodsMinorCategory>
          <itemDeliveryInstruction>
            <deadlineDate>1218</deadlineDate>
          </itemDeliveryInstruction>
          <itemID>
            <makerCode>0</makerCode>
            <gtin>04500000000346</gtin>
            <orderItemCode codeType="999">000001</orderItemCode>
            <name_sbcs>テストショウヒン1</name_sbcs>
          </itemID>
          <itemInfo>
            <itemSpec>
              <spec_sbcs>225250</spec_sbcs>
            </itemSpec>
            <color>
              <colorCode>20</colorCode>
              <description_sbcs>WHITE</description_sbcs>
            </color>
            <size>
              <sizeCode>245</sizeCode>
            </size>
          </itemInfo>
          <amounts>
            <itemNetPrice unitPrice="3999.00">27993</itemNetPrice>
            <itemSellingPrice unitPrice="7490">52430</itemSellingPrice>
          </amounts>
          <quantities>
            <unitMultiple>1</unitMultiple>
            <unitOfMeasure>00</unitOfMeasure>
            <orderQuantity>
              <quantity>7.0</quantity>
              <numOfOrderUnits>7</numOfOrderUnits>
            </orderQuantity>
          </quantities>
        </lineItem>
        <lineItem>
          <lineID>
            <lineNumber>05</lineNumber>
          </lineID>
          <goodsMinorCategory>
            <minorCategory>720</minorCategory>
            <detailedCategory>1115</detailedCategory>
          </goodsMinorCategory>
          <itemDeliveryInstruction>
            <deadlineDate>1218</deadlineDate>
          </itemDeliveryInstruction>
          <itemID>
            <makerCode>0</makerCode>
            <gtin>04500000000353</gtin>
            <orderItemCode codeType="999">000002</orderItemCode>
            <name_sbcs>テストショウヒン2</name_sbcs>
          </itemID>
          <itemInfo>
            <itemSpec>
              <spec_sbcs>225245</spec_sbcs>
            </itemSpec>
            <color>
              <colorCode>22</colorCode>
              <description_sbcs>WH/BLACK</description_sbcs>
            </color>
            <size>
              <sizeCode>225</sizeCode>
            </size>
          </itemInfo>
          <amounts>
            <itemNetPrice unitPrice="3999.00">3999</itemNetPrice>
            <itemSellingPrice unitPrice="7490">7490</itemSellingPrice>
          </amounts>
          <quantities>
            <unitMultiple>1</unitMultiple>
            <unitOfMeasure>00</unitOfMeasure>
            <orderQuantity>
              <quantity>1.0</quantity>
              <numOfOrderUnits>1</numOfOrderUnits>
            </orderQuantity>
          </quantities>
        </lineItem>
      </order>
      <order>
        <tradeID>
          <tradeNumber>99999926</tradeNumber>
        </tradeID>
        <parties>
          <shipTo>
            <code>6496</code>
            <gln>0</gln>
            <name_sbcs>ホッカイドウLC</name_sbcs>
          </shipTo>
          <receiver>
            <code>6496</code>
            <gln>0</gln>
            <name_sbcs>ホッカイドウLC</name_sbcs>
          </receiver>
          <transferOfOwnershipLocation>
            <code>6496</code>
            <gln>0</gln>
            <name_sbcs>ホッカイドウLC</name_sbcs>
          </transferOfOwnershipLocation>
          <payee>
            <code>0001</code>
            <gln>0</gln>
            <name_sbcs>テストトリヒキサキ</name_sbcs>
          </payee>
          <seller>
            <code>0001</code>
            <gln>0</gln>
            <name_sbcs>テストトリヒキサキ</name_sbcs>
          </seller>
        </parties>
        <logistics>
          <logisticsLabelInfo>
            <text_sbcs>Pプロパ</text_sbcs>
          </logisticsLabelInfo>
        </logistics>
        <tradeSummary>
          <goodsMajorCategory>
            <majorCategory>0</majorCategory>
            <subMajorCategory>0</subMajorCategory>
          </goodsMajorCategory>
          <dates>
            <orderDate>2018-11-29</orderDate>
            <deliveryDate>2018-12-03</deliveryDate>
            <deliveryDateToReceiver>2018-12-03</deliveryDateToReceiver>
            <transferOfOwnershipDate>2018-12-03</transferOfOwnershipDate>
          </dates>
          <note>
            <text_sbcs>ホンブ01 ホンデン チヤツカシテイビ     ケイカゴ ムコウ           </text_sbcs>
          </note>
        </tradeSummary>
        <lineItem>
          <lineID>
            <lineNumber>01</lineNumber>
          </lineID>
          <goodsMinorCategory>
            <minorCategory>720</minorCategory>
            <detailedCategory>1116</detailedCategory>
          </goodsMinorCategory>
          <itemDeliveryInstruction>
            <deadlineDate>1218</deadlineDate>
          </itemDeliveryInstruction>
          <itemID>
            <makerCode>0</makerCode>
            <gtin>04500000000360</gtin>
            <orderItemCode codeType="999">000002</orderItemCode>
            <name_sbcs>テストショウヒン2</name_sbcs>
          </itemID>
          <itemInfo>
            <itemSpec>
              <spec_sbcs>225245</spec_sbcs>
            </itemSpec>
            <color>
              <colorCode>22</colorCode>
              <description_sbcs>WH/BLACK</description_sbcs>
            </color>
            <size>
              <sizeCode>230</sizeCode>
            </size>
          </itemInfo>
          <amounts>
            <itemNetPrice unitPrice="3999.00">27993</itemNetPrice>
            <itemSellingPrice unitPrice="7490">52430</itemSellingPrice>
          </amounts>
          <quantities>
            <unitMultiple>1</unitMultiple>
            <unitOfMeasure>00</unitOfMeasure>
            <orderQuantity>
              <quantity>7.0</quantity>
              <numOfOrderUnits>7</numOfOrderUnits>
            </orderQuantity>
          </quantities>
        </lineItem>
        <lineItem>
          <lineID>
            <lineNumber>02</lineNumber>
          </lineID>
          <goodsMinorCategory>
            <minorCategory>720</minorCategory>
            <detailedCategory>1117</detailedCategory>
          </goodsMinorCategory>
          <itemDeliveryInstruction>
            <deadlineDate>1218</deadlineDate>
          </itemDeliveryInstruction>
          <itemID>
            <makerCode>0</makerCode>
            <gtin>04500000000377</gtin>
            <orderItemCode codeType="999">000002</orderItemCode>
            <name_sbcs>テストショウヒン2</name_sbcs>
          </itemID>
          <itemInfo>
            <itemSpec>
              <spec_sbcs>225245</spec_sbcs>
            </itemSpec>
            <color>
              <colorCode>22</colorCode>
              <description_sbcs>WH/BLACK</description_sbcs>
            </color>
            <size>
              <sizeCode>235</sizeCode>
            </size>
          </itemInfo>
          <amounts>
            <itemNetPrice unitPrice="3999.00">27993</itemNetPrice>
            <itemSellingPrice unitPrice="7490">52430</itemSellingPrice>
          </amounts>
          <quantities>
            <unitMultiple>1</unitMultiple>
            <unitOfMeasure>00</unitOfMeasure>
            <orderQuantity>
              <quantity>7.0</quantity>
              <numOfOrderUnits>7</numOfOrderUnits>
            </orderQuantity>
          </quantities>
        </lineItem>
        <lineItem>
          <lineID>
            <lineNumber>03</lineNumber>
          </lineID>
          <goodsMinorCategory>
            <minorCategory>720</minorCategory>
            <detailedCategory>1118</detailedCategory>
          </goodsMinorCategory>
          <itemDeliveryInstruction>
            <deadlineDate>1218</deadlineDate>
          </itemDeliveryInstruction>
          <itemID>
            <makerCode>0</makerCode>
            <gtin>04500000000384</gtin>
            <orderItemCode codeType="999">000002</orderItemCode>
            <name_sbcs>テストショウヒン2</name_sbcs>
          </itemID>
          <itemInfo>
            <itemSpec>
              <spec_sbcs>225245</spec_sbcs>
            </itemSpec>
            <color>
              <colorCode>22</colorCode>
              <description_sbcs>WH/BLACK</description_sbcs>
            </color>
            <size>
              <sizeCode>240</sizeCode>
            </size>
          </itemInfo>
          <amounts>
            <itemNetPrice unitPrice="3999.00">27993</itemNetPrice>
            <itemSellingPrice unitPrice="7490">52430</itemSellingPrice>
          </amounts>
          <quantities>
            <unitMultiple>1</unitMultiple>
            <unitOfMeasure>00</unitOfMeasure>
            <orderQuantity>
              <quantity>7.0</quantity>
              <numOfOrderUnits>7</numOfOrderUnits>
            </orderQuantity>
          </quantities>
        </lineItem>
        <lineItem>
          <lineID>
            <lineNumber>04</lineNumber>
          </lineID>
          <goodsMinorCategory>
            <minorCategory>720</minorCategory>
            <detailedCategory>1119</detailedCategory>
          </goodsMinorCategory>
          <itemDeliveryInstruction>
            <deadlineDate>1218</deadlineDate>
          </itemDeliveryInstruction>
          <itemID>
            <makerCode>0</makerCode>
            <gtin>04500000000391</gtin>
            <orderItemCode codeType="999">000002</orderItemCode>
            <name_sbcs>テストショウヒン2</name_sbcs>
          </itemID>
          <itemInfo>
            <itemSpec>
              <spec_sbcs>225245</spec_sbcs>
            </itemSpec>
            <color>
              <colorCode>22</colorCode>
              <description_sbcs>WH/BLACK</description_sbcs>
            </color>
            <size>
              <sizeCode>245</sizeCode>
            </size>
          </itemInfo>
          <amounts>
            <itemNetPrice unitPrice="3999.00">27993</itemNetPrice>
            <itemSellingPrice unitPrice="7490">52430</itemSellingPrice>
          </amounts>
          <quantities>
            <unitMultiple>1</unitMultiple>
            <unitOfMeasure>00</unitOfMeasure>
            <orderQuantity>
              <quantity>7.0</quantity>
              <numOfOrderUnits>7</numOfOrderUnits>
            </orderQuantity>
          </quantities>
        </lineItem>
        <lineItem>
          <lineID>
            <lineNumber>05</lineNumber>
          </lineID>
          <goodsMinorCategory>
            <minorCategory>720</minorCategory>
            <detailedCategory>1120</detailedCategory>
          </goodsMinorCategory>
          <itemDeliveryInstruction>
            <deadlineDate>1218</deadlineDate>
          </itemDeliveryInstruction>
          <itemID>
            <makerCode>0</makerCode>
            <gtin>04500000000407</gtin>
            <orderItemCode codeType="999">000003</orderItemCode>
            <name_sbcs>テストショウヒン3</name_sbcs>
          </itemID>
          <itemInfo>
            <itemSpec>
              <spec_sbcs>225250</spec_sbcs>
            </itemSpec>
            <color>
              <colorCode>20</colorCode>
              <description_sbcs>WHITE</description_sbcs>
            </color>
            <size>
              <sizeCode>230</sizeCode>
            </size>
          </itemInfo>
          <amounts>
            <itemNetPrice unitPrice="3999.00">27993</itemNetPrice>
            <itemSellingPrice unitPrice="7490">52430</itemSellingPrice>
          </amounts>
          <quantities>
            <unitMultiple>1</unitMultiple>
            <unitOfMeasure>00</unitOfMeasure>
            <orderQuantity>
              <quantity>7.0</quantity>
              <numOfOrderUnits>7</numOfOrderUnits>
            </orderQuantity>
          </quantities>
        </lineItem>
      </order>
    </order:listOfOrders>
  </common:message>
</sh:StandardBusinessDocument>

这是我的XSLT-我以为我有正确的答案,显然不是!

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:Extensions="Extensions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:common="urn:SecondGenEDI:common:Japan:1" xmlns:order="urn:SecondGenEDI:order:Japan:1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:template match="/">
      <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <xsl:for-each select="sh:StandardBusinessDocument/common:message/order:listOfOrders/">
            <OrderNumber>
            <xsl:value-of select = "order/tradeNumber"/>
           </OrderNumber>
         </xsl:for-each>
      </root>
   </xsl:template>
</xsl:stylesheet>

1 个答案:

答案 0 :(得分:1)

样式表中有两个错误:

  • 未定义sh名称空间前缀。
  • 选择不能以'/'结尾

此外,当前tradeNumber的select值不正确,无法检索到值。

尝试以下操作:

<xsl:stylesheet version="1.0" xmlns:Extensions="Extensions" 
xmlns:sh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:common="urn:SecondGenEDI:common:Japan:1" xmlns:order="urn:SecondGenEDI:order:Japan:1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:template match="/">
      <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <xsl:for-each select="sh:StandardBusinessDocument/common:message/order:listOfOrders">
            <OrderNumber>
            <xsl:value-of select="order/tradeID/tradeNumber"/>
           </OrderNumber>
         </xsl:for-each>
      </root>
   </xsl:template>
</xsl:stylesheet>