2014-09-22 4 views
0

OrderLineSource = YTR이없는 주문 만 표시하고 싶습니다. 다른 모든 표시되어야합니다 ....자식 값을 기준으로 부모를 제거 하시겠습니까?

내 샘플 XML :

<Orders> 
<Order> 
    <OrderID>34209649</OrderID> 
    <OrderStatus>checkout_complete</OrderStatus> 
    <Amount>32.93</Amount> 
    <OrderCreation>2014-02-08T00:00:03.00</OrderCreation> 
    <OrderCompletion>2014-02-08T00:00:03.00</OrderCompletion> 
    <CustomerGUID>303965683</CustomerGUID> 
    <CSMPurchaserGUID>0</CSMPurchaserGUID> 
    <Brand>TRFE</Brand> 
    <SourceECommerceSystem>Framework</SourceECommerceSystem> 
    <Currency>GBP</Currency> 
    <OrderChannel>Online</OrderChannel> 
    <TransactionSummary> 
    <TransactionID>2407065</TransactionID> 
    <MerchantReference>TEdV-5648-34209649</MerchantReference> 
    <CardCategory>Personal</CardCategory> 
    <CardScheme>VISA Debit</CardScheme> 
    <CardCountry>gbr</CardCountry> 
    <CardIssuer>sdfsdf sdf Bank asdf</CardIssuer> 
    <CardStartDate>0/0</CardStartDate> 
    <CardExpiryDate>2016/08</CardExpiryDate> 
    <Amount>32.93</Amount> 
    <Currency>GBP</Currency> 
    <CardPAN>************4585</CardPAN> 
    <Created>2014-02-07T23:56:48</Created> 
    <Updated>2014-02-08T00:00:03</Updated> 
    <ResponseStatusCode>1</ResponseStatusCode> 
    <ResponseStatusReason>FULFILLED OK</ResponseStatusReason> 
    <HostedPageIdentifier>dsfasdf-ee85-4afa-bb6a-0afc6dc99896</HostedPageIdentifier> 
    <HostedPageURL>https://hps.datacash.com/hps/</HostedPageURL> 
    <PaymentStatus>Paid</PaymentStatus> 
    <PaymentType>Debit Card</PaymentType> 
    <NameOnCard>Miss L J adsf</NameOnCard> 
    <DataCashRef>56456456454</DataCashRef> 
    <MerchantID>545646</MerchantID> 
    <ThreeDCard>1</ThreeDCard> 
    <ThreeDRequested>1</ThreeDRequested> 
    <IPAddress>127.89.560.1</IPAddress> 
    </TransactionSummary> 
    <OrderLine> 
    <OrderLineID>84598837</OrderLineID> 
    <OrderID>34209649</OrderID> 
    <OrderLineLabel>GAREGSBV</OrderLineLabel> 
    <OrderLineSource>GHR</OrderLineSource> 
    <Quantity>1</Quantity> 
    <UnitPrice>32.93</UnitPrice> 
    <Total>32.93</Total> 
    <SKUCode>P0032</SKUCode> 
    <Title>Miss.</Title> 
    <FirstName>ertwer</FirstName> 
    <FamilyName>sdaf</FamilyName> 
    <DateOfBirth>1984-05-30</DateOfBirth> 
    <Email>[email protected]</Email> 
    <Mobile>645646454</Mobile> 
    <PostChannel>0</PostChannel> 
    <TelephoneChannel>0</TelephoneChannel> 
    <EmailChannel>0</EmailChannel> 
    <TextAndOtherChannel>0</TextAndOtherChannel> 
    <BuildingNumber>27</BuildingNumber> 
    <AddressLine1>27</AddressLine1> 
    <AddressLine2>dsfasdf Road</AddressLine2> 
    <Town>London</Town> 
    <Country>sdfasdf er</Country> 
    <Postcode>KL7 2NS</Postcode> 
    <AddressValidated>1</AddressValidated> 
    <HKPolicy> 
     <PolicyNum>PP01754397</PolicyNum> 
     <ProductDescription>sadfsadfasdfgasdg</ProductDescription> 
     <CoverTypeDesc>Individual</CoverTypeDesc> 
     <SingleParentFamilyFlag>0</SingleParentFamilyFlag> 
     <PolicyTypeRefID>S</PolicyTypeRefID> 
     <PolicyTypeDesc>Sinasdfnce</PolicyTypeDesc> 
     <TierDesc>Classic</TierDesc> 
     <DestinationDesc>Worldwide including USA, Canada, Caribbean</DestinationDesc> 
     <TotalTravellers>1</TotalTravellers> 
     <NumOfAdults>1</NumOfAdults> 
     <NumOfUnder18>0</NumOfUnder18> 
     <PolicyStartDate>2014-02-08</PolicyStartDate> 
     <PolicyEndDate>2014-02-12</PolicyEndDate> 
     <BaseCost>32.93</BaseCost> 
     <Commission>11.18</Commission> 
     <UpsoldInd>0</UpsoldInd> 
     <TierRefID>C</TierRefID> 
     <DestinationRefID>W2</DestinationRefID> 
     <CoverTypeRefID>I</CoverTypeRefID> 
     <AONToPostPolicy>yes</AONToPostPolicy> 
     <SalesChannel>0011002</SalesChannel> 
     <WhereYouHeardOfUs>Press advertising</WhereYouHeardOfUs> 
     <TIPOLTraveller> 
      <TravellerUUID>1864-1</TravellerUUID> 
      <PolicyNum>PI0e31754397</PolicyNum> 
      <Title>Miss</Title> 
      <FirstName>sdfsf</FirstName> 
      <FamilyName>sdfsdf</FamilyName> 
      <DateOfBirth>1984-05-30</DateOfBirth> 
      <AgeBand>1864</AgeBand> 
      <DependentFlag>0</DependentFlag> 
     </TIPOLTraveller> 
    </TIPOLPolicy> 
    </OrderLine> 
    <OrderCustomerDetails> 
    <Title nil="true" /> 
    <FirstName nil="true" /> 
    <SecondName nil="true" /> 
    <FamilyName nil="true" /> 
    <DateOfBirth nil="true" /> 
    <Email nil="true" /> 
    <Telephone nil="true" /> 
    <Mobile nil="true" /> 
    <Gender nil="true" /> 
    <PostChannel nil="true" /> 
    <TelephoneChannel nil="true" /> 
    <EmailChannel nil="true" /> 
    <TextAndOtherChannel nil="true" /> 
    <BuildingNumber>27</BuildingNumber> 
    <AddressLine1>27</AddressLine1> 
    <AddressLine2>asdfa Road</AddressLine2> 
    <Town>asdfasdf</Town> 
    <Country>United dsf</Country> 
    <Postcode>KH9 2NS</Postcode> 
    <AddressValidated>1</AddressValidated> 
    </OrderCustomerDetails> 
</Order> 
<Order> 
    <OrderID>34209674</OrderID> 
    <OrderStatus>checkout_complete</OrderStatus> 
    <Amount>11.13</Amount> 
    <OrderCreation>2014-02-08T00:08:40.00</OrderCreation> 
    <OrderCompletion>2014-02-08T00:08:40.00</OrderCompletion> 
    <CustomerGUID>303965688</CustomerGUID> 
    <CSMPurchaserGUID>0</CSMPurchaserGUID> 
    <Brand>TRFDS</Brand> 
    <SourceECommerceSystem>Framework</SourceECommerceSystem> 
    <Currency>GBP</Currency> 
    <OrderChannel>Online</OrderChannel> 
    <TransactionSummary> 
    <TransactionID>8115032</TransactionID> 
    <MerchantReference>JHF-0800-34209674</MerchantReference> 
    <CardCategory>Personal</CardCategory> 
    <CardScheme>VISA Debit</CardScheme> 
    <CardCountry>gbr</CardCountry> 
    <CardIssuer>Unknown</CardIssuer> 
    <CardStartDate>0/0</CardStartDate> 
    <CardExpiryDate>2016/09</CardExpiryDate> 
    <Amount>11.13</Amount> 
    <Currency>GBP</Currency> 
    <CardPAN>************4849</CardPAN> 
    <Created>2014-02-08T00:08:00</Created> 
    <Updated>2014-02-08T00:08:40</Updated> 
    <ResponseStatusCode>1</ResponseStatusCode> 
    <ResponseStatusReason>FULFILLED OK</ResponseStatusReason> 
    <HostedPageIdentifier>f3306487-d6ea-4200-9eea-99b1d6832a2e</HostedPageIdentifier> 
    <HostedPageURL>https://hps.dat.com/hps/</HostedPageURL> 
    <PaymentStatus>Paid</PaymentStatus> 
    <PaymentType>Debit Card</PaymentType> 
    <NameOnCard>Miss Jor </NameOnCard> 
    <DataCashRef>380010093738013</DataCashRef> 
    <MerchantID>21877049</MerchantID> 
    <ThreeDCard>1</ThreeDCard> 
    <ThreeDRequested>1</ThreeDRequested> 
    <IPAddress>86..25640.99</IPAddress> 
    </TransactionSummary> 
    <OrderLine> 
    <OrderLineID>84598874</OrderLineID> 
    <OrderID>34209674</OrderID> 
    <OrderLineLabel>3-1008617753325</OrderLineLabel> 
    <OrderLineSource>YTR</OrderLineSource> 
    <Quantity>1</Quantity> 
    <UnitPrice>11.13</UnitPrice> 
    <Total>11.13</Total> 
    <Title>Miss.</Title> 
    <FirstName>Jordan</FirstName> 
    <SecondName>oirut</SecondName> 
    <FamilyName>dfgsdfgs</FamilyName> 
    <Email>[email protected]</Email> 
    <Mobile>654756464</Mobile> 
    <PostChannel>0</PostChannel> 
    <TelephoneChannel>0</TelephoneChannel> 
    <EmailChannel>0</EmailChannel> 
    <TextAndOtherChannel>0</TextAndOtherChannel> 
    <BuildingNumber>12</BuildingNumber> 
    <AddressLine1>12</AddressLine1> 
    <AddressLine2>sfgsdfg End Gardens</AddressLine2> 
    <Town>HEMEL sfgaefa</Town> 
    <Country>adf dgfsdfg</Country> 
    <Postcode>HP1 1SN</Postcode> 
    <OrderLineDetail> 
     <NameValuePair> 
      <Name>dfgsdfg</Name> 
      <Value>628</Value> 
     </NameValuePair> 
     <NameValuePair> 
      <Name>NameOnCard</Name> 
      <Value>adsfgasdgf Piper</Value> 
     </NameValuePair> 
     <NameValuePair> 
      <Name>DateOnCard</Name> 
      <Value>2014-02-05</Value> 
     </NameValuePair> 
     <NameValuePair> 
      <Name>CustomsOrSurcharge</Name> 
      <Value>CUSTOMS CHARGE TO PAY</Value> 
     </NameValuePair> 
    </OrderLineDetail> 
    </OrderLine> 
    <OrderCustomerDetails> 
    <Title>Miss.</Title> 
    <FirstName>Jordan</FirstName> 
    <SecondName>asdgfasdgf</SecondName> 
    <FamilyName nil="true" /> 
    <DateOfBirth /> 
    <Email>[email protected]</Email> 
    <Telephone /> 
    <Mobile>adfasdf</Mobile> 
    <Gender nil="true" /> 
    <PostChannel nil="true" /> 
    <TelephoneChannel nil="true" /> 
    <EmailChannel nil="true" /> 
    <TextAndOtherChannel nil="true" /> 
    <BuildingNumber>12</BuildingNumber> 
    <AddressLine1>12</AddressLine1> 
    <AddressLine2>adfasdf End Gardens</AddressLine2> 
    <Town>adsfasdf HEMPSTEAD</Town> 
    <Country>United asdfasdf</Country> 
    <Postcode>asd 1SN</Postcode> 
    </OrderCustomerDetails> 
</Order> 
</Orders> 

내가 XSLT를 사용하여 시도 :

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
<xsl:output method="xml" indent="yes"/> 
<!-- Orders --> 
<xsl:template match="/*"> 
<xsl:element name="Orders"> 
    <xsl:apply-templates select="./Order" /> 
</xsl:element> 
</xsl:template> 
<!-- Orders > Order --> 
<xsl:template match="/Order"> 
    <xsl:variable name="IsValid"> 
    <xsl:call-template name="HasOrIsValidPOLine" /> 
</xsl:variable> 
<xsl:if test="$IsValid='VALID'"> <!-- only display the order if there's a valid line under it--> 
    <xsl:element name="Order"> 
    <xsl:apply-templates select=".//VORNR" /> 
    </xsl:element> 
</xsl:if> 
</xsl:template> 
<!-- Part Order List > Part Order > Operational BO Number --> 
<xsl:template match="//VORNR"> 
<xsl:element name="./Order"> 
<xsl:apply-templates select="node()|@*"/> 
    <xsl:value-of select="text()"/> 
    </xsl:element> 
</xsl:template> 
<xsl:template name="HasOrIsValidPOLine"> 
<xsl:choose> 
    <xsl:when test="./OrderLineSource/text() != 'YTR'">VALID</xsl:when> 
    <xsl:otherwise>INVALID</xsl:otherwise> 
</xsl:choose> 
</xsl:template> 
<xsl:template match="node()|@*"> 
<xsl:copy> 
    <xsl:apply-templates select="node()|@*"/> 
</xsl:copy> 
</xsl:template> 

</xsl:stylesheet> 

당신이 나에게 솔루션을 제공하거나 알려 수는 어디 가고 잘못된

답변

1

먼저, 샘플 XML이 잘 형성되지 않은 : 그것은 폐쇄를 포함 </TIPOLPolicy> 태그가 시작 <HKPolicy> 태그와 일치하지 않습니다. 먼저 </HKPolicy>으로 변경하십시오.

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

    <!-- Identity transform --> 
    <!-- Default priority 0 for root node and -0.5 for the rest --> 
    <xsl:template match="/ | node() | @*"> 
     <xsl:copy> 
      <xsl:apply-templates select="node() | @*"/> 
     </xsl:copy> 
    </xsl:template> 

    <!-- Do nothing for Order elements whose OrderLine/OrderLineSource equals 'YTR' --> 
    <!-- Default priority 0.5 --> 
    <xsl:template match="Order[OrderLine/OrderLineSource = 'YTR']"/> 
</xsl:stylesheet> 

그것은 변환 및 다른 기본 우선 순위 신원을 사용합니다 : ID는 출력하지 않는 한에 낮은 기본 우선 순위 복사하여 입력을 변환 그 후

다음 XSLT 1.0 당신이 원하는 것을 주어진 입력 매치에 대해 더 높은 우선 순위를 갖는 다른 템플리트가 존재합니다. OrderLine/OrderLineSource 자손에 텍스트 값 'YTR'이 포함 된 Order 요소의 경우입니다. 기본 우선 순위가 높기 때문에 특정 템플릿이 ID 변환보다 우선합니다. 템플리트가 출력을 생성하지 않으므로 일치하는 Order 요소가 출력에서 ​​제거됩니다.

0
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="xml" indent="yes"/> 

    <xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template match="Order[OrderLine/OrderLineSource[string() = 'YTR']]"/> 

</xsl:stylesheet> 
관련 문제