Почему мой XSLT не извлекает правильные значения?«Ошибки таблицы стилей» - PullRequest
0 голосов
/ 17 апреля 2019

Я использую 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 Ответ

1 голос
/ 17 апреля 2019

В вашей таблице стилей есть две ошибки:

  • Префикс пространства имен sh не определен.
  • выбор не может заканчиваться символом '/'

Кроме того, в настоящее время значение select для tradeNumber является неправильным и не извлекает значение.

Попробуйте следующее:

<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>
...