Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt 是否基于子值删除父项?_Xslt - Fatal编程技术网

Xslt 是否基于子值删除父项?

Xslt 是否基于子值删除父项?,xslt,Xslt,我只想显示那些没有OrderLineSource=YTR的订单。应显示所有其他 我的示例XML: <Orders> <Order> <OrderID>34209649</OrderID> <OrderStatus>checkout_complete</OrderStatus> <Amount>32.93</Amount> <OrderCreation>2014-02-08T

我只想显示那些没有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>sdfasdfa@hotmail.com</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>dfgsdfg@hotmail.com</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>adfadf@hotmail.com</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>

34209649
结帐完成
32.93
2014-02-08T00:00:03.00
2014-02-08T00:00:03.00
303965683
0
TRFE
框架
英镑
在线 的
2407065
TEdV-5648-34209649
个人的
VISA借记卡
gbr
sdfsdf sdf银行asdf
0/0
2016/08
32.93
英镑
************4585
2014-02-07T23:56:48
2014-02-08T00:00:03
1.
满足了吗
dsfasdf-ee85-4afa-bb6a-0afc6dc99896
https://hps.datacash.com/hps/
支付
借记卡
L J adsf小姐
56456456454
545646
1.
1.
127.89.560.1
84598837
34209649
加列格斯伯夫
GHR
1.
32.93
32.93
P0032
错过。
埃特沃
sdaf
1984-05-30
sdfasdfa@hotmail.com
645646454
0
0
0
0
27
27
dsfasdf路
伦敦
sdfaser
KL7 2NS
1.
PP01754397
SADFSADFASDG
个人
0
s
Sinasdfnce
经典
全球范围内,包括美国、加拿大、加勒比海
1.
1.
0
2014-02-08
2014-02-12
32.93
11.18
0
C
W2
我
对
0011002
新闻广告
1864-1
PI0e31754397
错过
自卫队
sdfsdf
1984-05-30
1864
0
27
27
asdfa路
asdfasdf
联合dsf
KH9 2NS
1.
34209674
结帐完成
11.13
2014-02-08T00:08:40.00
2014-02-08T00:08:40.00
303965688
0
TRFDS
框架
英镑
在线 的
8115032
JHF-0800-34209674
个人的
VISA借记卡
gbr
不为人知
0/0
2016/09
11.13
英镑
************4849
2014-02-08T00:08:00
2014-02-08T00:08:40
1.
满足了吗
f3306487-d6ea-4200-9eea-99B1D6832E
https://hps.dat.com/hps/
支付
借记卡
乔小姐
380010093738013
21877049
1.
1.
86..25640.99
84598874
34209674
3-1008617753325
YTR
1.
11.13
11.13
错过。
乔丹
奥鲁特
dfgsdfgs
dfgsdfg@hotmail.com
654756464
0
0
0
0
12
12
sfgsdfg端花园酒店
希梅尔·斯斐法
adf dgfsdfg
HP1 1SN
dfgsdfg
628
名牌
adsfgasdgf吹管器
DateOnCard
2014-02-05
海关附加费
应付海关费用
错过。
乔丹
asdgfasdgf
adfadf@hotmail.com
adfasdf
12
12
阿德法斯花园酒店
HEMPSTEAD
联合asdfasdf
asd 1SN
我尝试使用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>

有效的
无效的
您能提供解决方案或告诉我哪里出了问题吗


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

首先,示例XML的格式不正确:它包含一个与起始标记不匹配的结束标记。首先将其更改为

在此之后,以下XSLT 1.0将完成您想要的操作:

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

它利用了标识转换和不同的默认优先级:具有较低默认优先级的标识转换将输入复制到输出,除非给定输入匹配存在具有较高优先级的另一个模板。这是订单元素的情况,其
OrderLine/OrderLineSource
子代包含文本值“YTR”。由于其较高的默认优先级,更具体的模板优先于标识转换。由于模板不生成任何输出,因此将从输出中删除任何匹配的
Order
元素