2017-10-10 64 views
0

我neeed来做XSLT这个XML转换到另一个地点:只显示其中EFFECTIVEDATE没有空,ratingChar1开始“WL” 我真的OT不明白我在做什么但这里是我的XSLT: 我neeed来做XSLT这个XML转换到另一个地点:仅示出EFFECTIVEDATE没有空,ratingChar1开始“WL” 我真的OT不明白我在做什么,但这里是我的xslt:删除父如果孩子空

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 
    <xsl:output method="xml" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> 

    <xsl:template match="effectiveDate[not('')]"/> 

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

    <xsl:template match="effectiveDate[@value=''] | parent[child[@value='']]" /> 
    <xsl:template match="ratingDataModel[descendant::ratingChar1[(starts-with(.,'WL'))]]"/> 
</xsl:transform> 

这是XML:

<EagleML eaglemlVersion="2-0" actualBuild="1" eaglemlType="ReferenceTransactionMessage" xmlns="http://www.eagleinvsys.com/2011/EagleML-2-0"> 
<header> 
    <batchIdentifier> 
     <batchId>ADX_A.20121214</batchId> 
     <sequenceNumber>44</sequenceNumber> 
     <totalCount>44</totalCount> 
    </batchIdentifier> 
    <sentBy>ALLSTATE</sentBy> 
    <creationTimestamp>2012-12-14T22:33:50.816-06:00</creationTimestamp> 
</header> 
<validation validationScheme="Allstate" xmlns="http://www.eagleinvsys.com/2011/EagleML-2-0">Allstate</validation> 
<party id="Allstate" xmlns="http://www.eagleinvsys.com/2011/EagleML-2-0"> 
    <partyId>Allstate</partyId> 
    <partyName>Allstate Investments</partyName> 
</party> 
<referenceTransaction> 
    <header> 
     <identifier id="Allstate"> 
      <transactionId transactionIdScheme="Allstate">Allstate</transactionId> 
     </identifier> 
    </header> 
    <rating> 
     <sourceName>ALADDIN</sourceName> 
     <updateSource>ALDDNGAL</updateSource> 
     <effectiveDate>2012-12-14</effectiveDate> 
     <ratingDataModel> 
      <alphaRating>2</alphaRating> 
      <submittedBy>l5mbeatt</submittedBy> 
      <submittedDate>2012-12-14T15:57:29-06:00</submittedDate> 
      <ratingCode>RV_2</ratingCode> 
      <ratingTypeIndicator/> 
      <ratingChar1>RV_2</ratingChar1> 
     </ratingDataModel> 
    </rating> 
</referenceTransaction> 
<referenceTransaction> 
    <header> 
     <identifier id="Allstate"> 
      <transactionId transactionIdScheme="Allstate">Allstate</transactionId> 
     </identifier> 
    </header> 
    <rating> 
     <sourceName>ALADDIN</sourceName> 
     <updateSource>ALDDNGAL</updateSource> 
     <effectiveDate>2012-12-14</effectiveDate> 
     <ratingDataModel> 
      <alphaRating>45</alphaRating> 
      <submittedBy>l5mbeatt</submittedBy> 
      <submittedDate>2012-12-14T15:57:29-06:00</submittedDate> 
      <ratingCode>TH_45</ratingCode> 
      <ratingTypeIndicator/> 
      <ratingChar1>TH_45</ratingChar1> 
     </ratingDataModel> 
    </rating> 
</referenceTransaction> 
<referenceTransaction> 
    <header> 
     <identifier id="Allstate"> 
      <transactionId transactionIdScheme="Allstate">Allstate</transactionId> 
     </identifier> 
    </header> 
    <rating> 
     <sourceName>ALADDIN</sourceName> 
     <updateSource>ALDDNGAL</updateSource> 
     <effectiveDate>2012-12-14</effectiveDate> 
     <ratingDataModel> 
      <alphaRating>CONCERN</alphaRating> 
      <submittedBy>l5bprice</submittedBy> 
      <submittedDate>2012-12-14T15:43:59-06:00</submittedDate> 
      <ratingCode>WL_CONCERN</ratingCode> 
      <ratingTypeIndicator>WATCHLIST</ratingTypeIndicator> 
      <ratingChar1>WL_CONCERN</ratingChar1> 
      <ratingDate1>2012-12-14</ratingDate1> 
     </ratingDataModel> 
    </rating> 
</referenceTransaction> 
<referenceTransaction> 
    <header> 
     <identifier id="Allstate"> 
      <transactionId transactionIdScheme="Allstate">Allstate</transactionId> 
     </identifier> 
    </header> 
    <rating> 
     <sourceName>ALADDIN</sourceName> 
     <updateSource>ALDDNGAL</updateSource> 
     <effectiveDate></effectiveDate> 
     <ratingDataModel> 
      <alphaRating>CONCERN</alphaRating> 
      <submittedBy>nfallon</submittedBy> 
      <submittedDate>2012-12-14T16:05:25-06:00</submittedDate> 
      <ratingCode>WL_CONCERN</ratingCode> 
      <ratingTypeIndicator>WATCHLIST</ratingTypeIndicator> 
      <ratingChar1>WL_CONCERN</ratingChar1> 
      <ratingDate1>2012-12-14</ratingDate1> 
     </ratingDataModel> 
    </rating> 
</referenceTransaction> 
</EagleML> 

预期的XML:

<EagleML eaglemlVersion="2-0" actualBuild="1" eaglemlType="ReferenceTransactionMessage" xmlns="http://www.eagleinvsys.com/2011/EagleML-2-0"> 
<header> 
    <batchIdentifier> 
     <batchId>ADX_A.20121214</batchId> 
     <sequenceNumber>44</sequenceNumber> 
     <totalCount>44</totalCount> 
    </batchIdentifier> 
    <sentBy>ALLSTATE</sentBy> 
    <creationTimestamp>2012-12-14T22:33:50.816-06:00</creationTimestamp> 
</header> 
<validation validationScheme="Allstate" xmlns="http://www.eagleinvsys.com/2011/EagleML-2-0">Allstate</validation> 
<party id="Allstate" xmlns="http://www.eagleinvsys.com/2011/EagleML-2-0"> 
    <partyId>Allstate</partyId> 
    <partyName>Allstate Investments</partyName> 
</party> 
<referenceTransaction> 
    <header> 
     <identifier id="Allstate"> 
      <transactionId transactionIdScheme="Allstate">Allstate</transactionId> 
     </identifier> 
    </header> 
    <rating> 
     <sourceName>ALADDIN</sourceName> 
     <updateSource>ALDDNGAL</updateSource> 
     <effectiveDate>2012-12-14</effectiveDate> 
     <ratingDataModel> 
      <alphaRating>CONCERN</alphaRating> 
      <submittedBy>l5bprice</submittedBy> 
      <submittedDate>2012-12-14T15:43:59-06:00</submittedDate> 
      <ratingCode>WL_CONCERN</ratingCode> 
      <ratingTypeIndicator>WATCHLIST</ratingTypeIndicator> 
      <ratingChar1>WL_CONCERN</ratingChar1> 
      <ratingDate1>2012-12-14</ratingDate1> 
     </ratingDataModel> 
    </rating> 
</referenceTransaction> 
</EagleML> 
+0

你能编辑你的问题来显示在这种情况下的预期输出?谢谢。 –

回答

0

如果您正在寻找排除某些referenceTransaction元素,你真的需要匹配referenceTransaction,在[]条件的模板。就条件而言,你应该改变逻辑。你应该否定它,而不是为了保留你想要保留的条件,而是给出你想要删除的条件。

<xsl:template match="referenceTransaction 
         [rating/effectiveDate='' or not(starts-with(rating/ratingDataModel/ratingChar1,'WL'))]"/> 

即删除referenceTransaction如果effectiveDate为空或ratingChar1WL启动。

但是,您有第二个问题。在您的XML中,您有默认名称空间

xmlns="http://www.eagleinvsys.com/2011/EagleML-2-0" 

但是您在XSLT中没有考虑到这一点。如果您确实使用XSLT 2.0,则可以使用xpath-default-namespace来处理此问题。

试试这个XSLT

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xpath-default-namespace="http://www.eagleinvsys.com/2011/EagleML-2-0"> 
    <xsl:output method="xml" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> 

    <xsl:strip-space elements="*" /> 

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

    <xsl:template match="referenceTransaction[rating/effectiveDate='' or not(starts-with(rating/ratingDataModel/ratingChar1,'WL'))]"/> 
</xsl:transform> 

但是,如果你正在使用XSLT 1.0,你必须定义一个名字空间前缀和使用模板匹配

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:eml="http://www.eagleinvsys.com/2011/EagleML-2-0"> 
    <xsl:output method="xml" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> 

    <xsl:strip-space elements="*" /> 

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

    <xsl:template match="eml:referenceTransaction[eml:rating/eml:effectiveDate='' or not(starts-with(eml:rating/eml:ratingDataModel/eml:ratingChar1,'WL'))]"/> 
</xsl:transform> 
0

试试这个

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:a="http://www.eagleinvsys.com/2011/EagleML-2-0" 
    version="2.0"> 
    <xsl:output method="xml" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> 


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

    <xsl:template match="a:referenceTransaction[normalize-space(descendant::a:effectiveDate)='' and starts-with(descendant::a:ratingChar1, 'WL')]"/> 

</xsl:transform>