使用xpath标识节点

时间:2015-06-30 09:38:24

标签: xslt xpath xslt-1.0

我使用的是xslt 1.0,我有以下xml doc:

    <ns0:Root xmlns:ns0="http://schemas.microsoft.com/BizTalk/2003/aggschema">
  <InputMessagePart_0>
    <ns1:ArrayOfArticleMasterDTO xmlns:ns1="http://BTS.GO.FactFeeds/DC_ArticleMaster">
      <ArticleMasterDTO>
        <AltBarcodes>
          <string>10</string>
        </AltBarcodes>
        <ClientId>ClientId_0</ClientId>
        <ArticleID>10</ArticleID>
        <ArticleReference>ArticleReference_0</ArticleReference>
        <ArticleSize>ArticleSize_0</ArticleSize>
        <ArticleStyle>10</ArticleStyle>
        <ArticleFit>ArticleFit_0</ArticleFit>
        <SupplierID>10</SupplierID>
        <Description>Description_0</Description>
        <Sku>Sku_0</Sku>
        <UnitsPerCase>125</UnitsPerCase>
        <UnitsPerLayer>UnitsPerLayer_0</UnitsPerLayer>
        <UnitsPerPallet>UnitsPerPallet_0</UnitsPerPallet>
        <LayersPerPallet>LayersPerPallet_0</LayersPerPallet>
        <FullPalletWeightKG>FullPalletWeightKG_0</FullPalletWeightKG>
        <CaseLengthMM>CaseLengthMM_0</CaseLengthMM>
        <CaseHeightMM>CaseHeightMM_0</CaseHeightMM>
        <CaseDepthMM>CaseDepthMM_0</CaseDepthMM>
        <CaseWeightG>CaseWeightG_0</CaseWeightG>
        <Colour>Colour_0</Colour>
        <Level1Description>Level1Description_0</Level1Description>
        <Level2Description>Level2Description_0</Level2Description>
        <Level3Description>Level3Description_0</Level3Description>
        <Level4Description>Level4Description_0</Level4Description>
        <OuterCartonBarcode>OuterCartonBarcode_0</OuterCartonBarcode>
        <PrimaryBarcode>PrimaryBarcode_0</PrimaryBarcode>
      </ArticleMasterDTO>
    </ns1:ArrayOfArticleMasterDTO>
  </InputMessagePart_0>
  <InputMessagePart_1>
    <ns2:SelectResponse xmlns:ns2="http://Microsoft.LobServices.OracleDB/2007/03/USER_DWDEV/Table/DW_PACK_BARCODES">
      <ns2:SelectResult>
        <ns2:DW_PACK_BARCODESRECORDSELECT>
          <ns2:PRODUCT_ID>71</ns2:PRODUCT_ID>
          <ns2:SYS_BARCODE>SYS_BARCODES</ns2:SYS_BARCODE>
          <ns2:PACK_TYPE>PACK_T</ns2:PACK_TYPE>
          <ns2:CHECK_DIGIT_PACK_BARCODE>CHECK_DIGIT_PA</ns2:CHECK_DIGIT_PACK_BARCODE>
          <ns2:PACK_BARCODE>PACK_BARCODEP</ns2:PACK_BARCODE>
          <ns2:CHECK_DIGIT_CARTON_BARCODE>CHECK_DIGIT_CA</ns2:CHECK_DIGIT_CARTON_BARCODE>
          <ns2:CARTON_BARCODE>CARTON_BARCOD</ns2:CARTON_BARCODE>
          <ns2:IN_DATE>1999-05-31T13:20:00.000-05:00</ns2:IN_DATE>
          <ns2:UP_DATE>1999-05-31T13:20:00.000-05:00</ns2:UP_DATE>
          <ns2:CREATEDTIME>1999-05-31T13:20:00.000-05:00</ns2:CREATEDTIME>
        </ns2:DW_PACK_BARCODESRECORDSELECT>
        <ns2:DW_PACK_BARCODESRECORDSELECT>
          <ns2:PRODUCT_ID>79</ns2:PRODUCT_ID>
          <ns2:SYS_BARCODE>SYS_BARCODES</ns2:SYS_BARCODE>
          <ns2:PACK_TYPE>PACK_T</ns2:PACK_TYPE>
          <ns2:CHECK_DIGIT_PACK_BARCODE>CHECK_DIGIT_PA</ns2:CHECK_DIGIT_PACK_BARCODE>
          <ns2:PACK_BARCODE>PACK_BARCODEP</ns2:PACK_BARCODE>
          <ns2:CHECK_DIGIT_CARTON_BARCODE>CHECK_DIGIT_CA</ns2:CHECK_DIGIT_CARTON_BARCODE>
          <ns2:CARTON_BARCODE>CARTON_BARCOD</ns2:CARTON_BARCODE>
          <ns2:IN_DATE>1999-05-31T13:20:00.000-05:00</ns2:IN_DATE>
          <ns2:UP_DATE>1999-05-31T13:20:00.000-05:00</ns2:UP_DATE>
          <ns2:CREATEDTIME>1999-05-31T13:20:00.000-05:00</ns2:CREATEDTIME>
        </ns2:DW_PACK_BARCODESRECORDSELECT>
        <ns2:DW_PACK_BARCODESRECORDSELECT>
          <ns2:PRODUCT_ID>78</ns2:PRODUCT_ID>
          <ns2:SYS_BARCODE>SYS_BARCODES</ns2:SYS_BARCODE>
          <ns2:PACK_TYPE>PACK_T</ns2:PACK_TYPE>
          <ns2:CHECK_DIGIT_PACK_BARCODE>CHECK_DIGIT_PA</ns2:CHECK_DIGIT_PACK_BARCODE>
          <ns2:PACK_BARCODE>PACK_BARCODEP</ns2:PACK_BARCODE>
          <ns2:CHECK_DIGIT_CARTON_BARCODE>CHECK_DIGIT_CA</ns2:CHECK_DIGIT_CARTON_BARCODE>
          <ns2:CARTON_BARCODE>CARTON_BARCOD</ns2:CARTON_BARCODE>
          <ns2:IN_DATE>1999-05-31T13:20:00.000-05:00</ns2:IN_DATE>
          <ns2:UP_DATE>1999-05-31T13:20:00.000-05:00</ns2:UP_DATE>
          <ns2:CREATEDTIME>1999-05-31T13:20:00.000-05:00</ns2:CREATEDTIME>
        </ns2:DW_PACK_BARCODESRECORDSELECT>
      </ns2:SelectResult>
    </ns2:SelectResponse>
  </InputMessagePart_1>
</ns0:Root>

我希望xpath从根目录中选择 节点。我可以使用以下非常长的xpath进行选择,但是当我尝试使用名称空间前缀(如ns2)时:我没有选择。任何人都可以提供比下面更短的xpath选择吗?

/*[local-name()='Root' and
namespace-uri()='http://schemas.microsoft.com/BizTalk/2003/aggschema']/*[local-name()='InputMessagePart_1'
and namespace-uri()='']/*[local-name()='SelectResponse' and
namespace-uri()='http://Microsoft.LobServices.OracleDB/2007/03/USER_DWDEV/Table/DW_PACK_BARCODES']/*[local-name()='SelectResult'
and
namespace-uri()='http://Microsoft.LobServices.OracleDB/2007/03/USER_DWDEV/Table/DW_PACK_BARCODES']/*[local-name()='DW_PACK_BARCODESRECORDSELECT'
and
namespace-uri()='http://Microsoft.LobServices.OracleDB/2007/03/USER_DWDEV/Table/DW_PACK_BARCODES']

1 个答案:

答案 0 :(得分:2)

我认为您只需要在XSL-T的根目录上声明使用的命名空间,例如:

ivar

然后,您将能够在XPath表达式中使用前缀,并且您的XPath将转向:

readwrite