need to identify duplicates with a condtional param in xslt1.0

﹥>﹥吖頭↗ 提交于 2019-12-11 09:09:33

问题


Here is my input

<depositAccount>
  <EligibleDepAccount>
    <type>DDA</type>
    <market>050</market>
    <number>12345678</number>
    <status>Y</status>
    <relationship>F-N</relationship>
    <productCode>ICK</productCode>
    <packageCode/>
    <primaryIndicator>N</primaryIndicator>
    <customer1DrivBen/>
    <customer2Relationship>O-N</customer2Relationship>
    <customer2DrivBen/>
    <customer3Relationship/>
    <customer3DrivBen/>
    <customer3CifKey/>
    <tierDetail>
      <level>0</level>
      <violationCounter>0</violationCounter>
      <enrollmentDate>0</enrollmentDate>
    </tierDetail>
    <TIEligible>false</TIEligible>
  </EligibleDepAccount>
  <EligibleDepAccount>
    <type>DDA</type>
    <market>050</market>
    <number>99999999</number>
    <status>Y</status>
    <relationship>F-N</relationship>
    <productCode>ICK</productCode>
    <packageCode>PDM</packageCode>
    <primaryIndicator>N</primaryIndicator>
    <customer1DrivBen/>
    <customer2Relationship>O-N</customer2Relationship>
    <customer2DrivBen/>
    <customer3Relationship/>
    <customer3DrivBen/>
    <customer3CifKey/>
    <tierDetail>
      <level>0</level>
      <violationCounter>0</violationCounter>
      <enrollmentDate>0</enrollmentDate>
    </tierDetail>
    <TIEligible>false</TIEligible>
  </EligibleDepAccount>
  <EligibleDepAccount>
    <type>DDA</type>
    <market>050</market>
    <number>12345678</number>
    <status>N</status>
    <productCode>KDB</productCode>
    <TIEligible>false</TIEligible>
  </EligibleDepAccount>
  <EligibleDepAccount>
    <type>DDA</type>
    <market>050</market>
    <number>85677833</number>
    <status>N</status>
    <productCode>KDB</productCode>
    <TIEligible>false</TIEligible>
  </EligibleDepAccount>
</depositAccount>

I need to find out same account number objects and check if the status is Y , then pull that object. I used the below code

<xsl:for-each-group select="$depositAccount/EligibleDepAccount" group-by="number">  
  <xsl:variable name="stat" select="$depositAccount/EligibleDepAccount/status/text()" />
  <xsl:if test="count(current-group()) = 2">
    <xsl:copy-of select="current-group()[1]"/>              
  </xsl:if>
  <xsl:if test="count(current-group()) = 1 and $stat = 'Y'">
    <xsl:copy-of select="."/>               
  </xsl:if>
</xsl:for-each-group>

In the above code, test="count(current-group()) = 1 and $stat = 'Y' doesn't seem to work at all.


回答1:


You use for-each-group but tag the question as xslt-1.0, that does not make sense.

Assuming an XSLT 2.0 processor I think you simply want

<xsl:for-each-group select="$depositAccount/EligibleDepAccount[status = 'Y']" group-by="number"> 
  <xsl:copy-of select="."/>
</xsl:for-each-group>


来源:https://stackoverflow.com/questions/20031452/need-to-identify-duplicates-with-a-condtional-param-in-xslt1-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!