如何使用子XML元素中的值使用** XSLT 1.0 **删除** XML层次结构元素?

时间:2019-05-10 14:04:43

标签: xml xslt xslt-1.0

我从查找API获取响应XML,该API回撤了已过期的重复值,我想使用 XSLT 1.0 删除过期的重复响应 XML 1.0 元素,因此仅显示实时响应详细信息以进行进一步处理。如果XML元素等于“ E”,则该元素已过期,我希望在XSLT转换后排除该元素;如果它等于“ L”,则它是Live,并且我希望该XML层次结构部分的所有元素。

使用过期和实时元素响应XML

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soap:Body>
      <GetFullSiteCollectionsResponse xmlns="http://webservices.whitespacews.com/">
         <GetFullSiteCollectionsResult>
            <ErrorCode>0</ErrorCode>
            <ErrorDescription>Success</ErrorDescription>
            <SuccessFlag>true</SuccessFlag>
            <SiteServices>
               <ApiSiteServiceWithExtraDetails>
                  <SiteService>                         
                     <ContractName>Garden Waste Collection Service Contract</ContractName>
                     <ContractDescription>Garden Waste Collection Service Contract</ContractDescription>                         
                     <SiteContractID>109085</SiteContractID>
                     <ContractStatusCode>E</ContractStatusCode> THIS ELEMENT HERE IS EXPIRED AND I WANT THIS SECTION EXCLUDING
                     <EWCCode />
                     <SiteServiceItemQuantity>4.0000</SiteServiceItemQuantity>
                     <SiteServiceItemID>151994</SiteServiceItemID>
                     <NextCollectionDate xsi:nil="true" />
                  </SiteService>
               </ApiSiteServiceWithExtraDetails>
               <ApiSiteServiceWithExtraDetails>
                  <SiteService>                         
                     <ContractName>Garden Waste Collection Service Contract</ContractName>
                     <ContractDescription>Garden Waste Collection Service Contract</ContractDescription>                         
                     <SiteContractID>109078</SiteContractID>
                     <ContractStatusCode>E</ContractStatusCode> THIS ELEMENT HERE IS EXPIRED AND I WANT THIS SECTION EXCLUDING
                     <EWCCode />
                     <SiteServiceItemQuantity>4.0000</SiteServiceItemQuantity>
                     <SiteServiceItemID>151987</SiteServiceItemID>
                     <NextCollectionDate xsi:nil="true" />
                  </SiteService>
               </ApiSiteServiceWithExtraDetails>
               <ApiSiteServiceWithExtraDetails>
                  <SiteService>                         
                     <ContractName>Recycling Collection Service Contract</ContractName>
                     <ContractDescription>Recycling Collection Service Contract</ContractDescription>                         
                     <SiteContractID>70155</SiteContractID>
                     <ContractStatusCode>L</ContractStatusCode>  THIS ELEMENT HERE IS LIVE AND I WANT THIS SECTION INCLUDING
                     <EWCCode />
                     <SiteServiceItemQuantity>1.0000</SiteServiceItemQuantity>
                     <SiteServiceItemID>106432</SiteServiceItemID>
                     <NextCollectionDate>2019-05-23T00:00:00</NextCollectionDate>
                  </SiteService>
               </ApiSiteServiceWithExtraDetails>
            </SiteServices>
         </GetFullSiteCollectionsResult>
      </GetFullSiteCollectionsResponse>
   </soap:Body>
</soap:Envelope>

仅遵循XSLT转换的所需XML,仅显示实时XML元素

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soap:Body>
      <GetFullSiteCollectionsResponse xmlns="http://webservices.whitespacews.com/">
         <GetFullSiteCollectionsResult>
            <ErrorCode>0</ErrorCode>
            <ErrorDescription>Success</ErrorDescription>
            <SuccessFlag>true</SuccessFlag>
            <SiteServices>                  
               <ApiSiteServiceWithExtraDetails>
                  <SiteService>                         
                     <ContractName>Recycling Collection Service Contract</ContractName>
                     <ContractDescription>Recycling Collection Service Contract</ContractDescription>                         
                     <SiteContractID>70155</SiteContractID>
                     <ContractStatusCode>L</ContractStatusCode>  THIS ELEMENT HERE IS LIVE AND I WANT THIS SECTION INCLUDING
                     <EWCCode />
                     <SiteServiceItemQuantity>1.0000</SiteServiceItemQuantity>
                     <SiteServiceItemID>106432</SiteServiceItemID>
                     <NextCollectionDate>2019-05-23T00:00:00</NextCollectionDate>
                  </SiteService>
               </ApiSiteServiceWithExtraDetails>
            </SiteServices>
         </GetFullSiteCollectionsResult>
      </GetFullSiteCollectionsResponse>
   </soap:Body>
</soap:Envelope>

0 个答案:

没有答案