XSLT提取值

时间:2013-07-10 08:39:04

标签: xml wcf xslt xml-namespaces

我们有一个申请。应用程序中的Web服务基于WCF。

请参阅下面我从应用程序获取的响应xml。我正在努力弄清楚如何从应用程序中提取某些值。有很多内联xmlns声明。

这是我从应用程序中获取的输入xml:

<?xml version="1.0" encoding="UTF-8" ?>
<RequestSelectionValuesResponse xmlns="http://www.camstar.com/WebService/WSShopFloor" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <RequestSelectionValuesResult>true</RequestSelectionValuesResult>
    <serviceInfo xmlns:q3="http://www.camstar.com/WebService/DataTypes" q3:type="OnlineQuery_Info">
      <OnlineQuerySelection>
        <RequestValue>false</RequestValue>
        <RequestMetadata>false</RequestMetadata>
        <RequestSubFieldValues>false</RequestSubFieldValues>
        <RequestSelectionValues>true</RequestSelectionValues>
        <SelectionValuesInput/>
        <SelectionValues>
          <RecordSetHeader>
            <ColumnCount>12</ColumnCount>
            <ColumnHeaders>
              <__listItem>
                <Name>No</Name>
                <FieldType>
                  <GenericType>Float</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>LotId</Name>
                <FieldType>
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>VendorCommitDate</Name>
                <FieldType>    
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>Operation</Name>
                <FieldType>
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>ProcessCode</Name>
                <FieldType>                         
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>DieQty</Name>
                <FieldType>
                  <GenericType>Float</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>WaferQty</Name>
                <FieldType>
                  <GenericType>Float</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>HardwareProductid</Name>
                <FieldType>
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>NoOfLot</Name>
                <FieldType>
                  <GenericType>Float</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>Status</Name>
                <FieldType>
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>InQueue</Name>
                <FieldType>
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>Multiple_Lot_Matched</Name>
                <FieldType>
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
            </ColumnHeaders>
          </RecordSetHeader>
          <Data>
            <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
              <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msdata:EnforceConstraints="False">
                <xs:complexType>
                  <xs:choice minOccurs="0" maxOccurs="unbounded">
                    <xs:element name="Table1">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="No" type="xs:string" minOccurs="0"/>
                          <xs:element name="LotId" type="xs:string" minOccurs="0"/>
                          <xs:element name="VendorCommitDate" type="xs:string" minOccurs="0"/>
                          <xs:element name="Operation" type="xs:string" minOccurs="0"/>
                          <xs:element name="ProcessCode" type="xs:string" minOccurs="0"/>
                          <xs:element name="DieQty" type="xs:string" minOccurs="0"/>
                          <xs:element name="WaferQty" type="xs:string" minOccurs="0"/>
                          <xs:element name="HardwareProductid" type="xs:string" minOccurs="0"/>
                          <xs:element name="NoOfLot" type="xs:string" minOccurs="0"/>
                          <xs:element name="Status" type="xs:string" minOccurs="0"/>
                          <xs:element name="InQueue" type="xs:string" minOccurs="0"/>
                          <xs:element name="Multiple_Lot_Matched" type="xs:string" minOccurs="0"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:choice>
                </xs:complexType>
              </xs:element>
            </xs:schema>
            <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
              <NewDataSet xmlns="http://www.camstar.com/WebService/DataTypes">
                <Table1 diffgr:id="Table11" msdata:rowOrder="0" diffgr:hasChanges="inserted">
                  <No>1</No>
                  <LotId>5000018</LotId>
                  <VendorCommitDate>07-31-2013</VendorCommitDate>
                  <Operation>SORT</Operation>
                  <ProcessCode>SO</ProcessCode>
                  <DieQty>2500</DieQty>
                  <WaferQty>25</WaferQty>
                  <HardwareProductid>Hardware_Prod_for_5000018</HardwareProductid>
                  <NoOfLot>2</NoOfLot>
                  <Status>OPEN</Status>
                  <InQueue>NO</InQueue>
                  <Multiple_Lot_Matched>TRUE</Multiple_Lot_Matched>
                </Table1>
                <Table1 diffgr:id="Table12" msdata:rowOrder="1" diffgr:hasChanges="inserted">
                  <No>2</No>
                  <LotId>5000019</LotId>
                  <VendorCommitDate>08-31-2013</VendorCommitDate>
                  <Operation>SORT</Operation>
                  <ProcessCode>SO</ProcessCode>
                  <DieQty>50000</DieQty>
                  <WaferQty>25</WaferQty>
                  <HardwareProductid>Hardware_Prod_for_5000019</HardwareProductid>
                  <NoOfLot>2</NoOfLot>
                  <Status>OPEN</Status>
                  <InQueue>YES</InQueue>
                  <Multiple_Lot_Matched>TRUE</Multiple_Lot_Matched>
                </Table1>
              </NewDataSet>
            </diffgr:diffgram>
          </Data>
        </SelectionValues>
      </OnlineQuerySelection>
    </serviceInfo>
    <resultStatus xmlns:q1="http://www.camstar.com/WebService/DataTypes" xsi:type="q1:ResultStatus">
      <Message xmlns="http://www.camstar.com/WebService/DataTypes">Update completed successfully</Message>
      <IsError xmlns="http://www.camstar.com/WebService/DataTypes">false</IsError>
    </resultStatus>
  </RequestSelectionValuesResponse>

从上面的XML我需要提取这些值(Table1下的所有值):

<Table1 diffgr:id="Table11" msdata:rowOrder="0" diffgr:hasChanges="inserted">
  <No>1</No>
  <LotId>5000018</LotId>
  <VendorCommitDate>07-31-2013</VendorCommitDate>
  <Operation>SORT</Operation>
  <ProcessCode>SO</ProcessCode>
  <DieQty>2500</DieQty>
  <WaferQty>25</WaferQty>
  <HardwareProductid>Hardware_Prod_for_5000018</HardwareProductid>
  <NoOfLot>2</NoOfLot>
  <Status>OPEN</Status>
  <InQueue>NO</InQueue>
  <Multiple_Lot_Matched>TRUE</Multiple_Lot_Matched>
</Table1>
<Table1 diffgr:id="Table12" msdata:rowOrder="1" diffgr:hasChanges="inserted">
  <No>2</No>
  <LotId>5000019</LotId>
  <VendorCommitDate>08-31-2013</VendorCommitDate>
  <Operation>SORT</Operation>
  <ProcessCode>SO</ProcessCode>
  <DieQty>50000</DieQty>
  <WaferQty>25</WaferQty>
  <HardwareProductid>Hardware_Prod_for_5000019</HardwareProductid>
  <NoOfLot>2</NoOfLot>
  <Status>OPEN</Status>
  <InQueue>YES</InQueue>
  <Multiple_Lot_Matched>TRUE</Multiple_Lot_Matched>
</Table1>

如何解决这个问题?任何帮助非常感谢。感谢

1 个答案:

答案 0 :(得分:0)

不确定如何提取它。以下是使用XSLT的解决方案:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:d="http://www.camstar.com/WebService/DataTypes">

  <xsl:output omit-xml-declaration="yes"/>

  <xsl:template match="/">
    <xsl:for-each select="//d:NewDataSet/d:Table1">
      <xsl:copy-of select="." />
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>