【问题标题】:need to identify duplicates with a condtional param in xslt1.0需要在 xslt 1.0 中识别没有条件参数的重复项
【发布时间】:2013-11-17 13:50:49
【问题描述】:

这是我的意见

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

我需要找出相同的帐号对象并检查状态是否为 Y ,然后拉出该对象。我使用了下面的代码

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

在上面的代码中,test="count(current-group()) = 1 and $stat = 'Y' 似乎根本不起作用。

【问题讨论】:

    标签: xslt xslt-2.0


    【解决方案1】:

    您使用for-each-group,但将问题标记为xslt-1.0,这没有意义。

    假设您只是想要一个 XSLT 2.0 处理器

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

    【讨论】:

    • 谢谢你,马丁,这很完美,我很抱歉作为 xslt-1.0 安装。问题,有时可能没有重复进入,我仍然想捕获一个进入的元素,这仍然有效吗?
    • 是的,for-each-group 当然也会构建单个元素的组,如果只有一个具有某个 number 的单个元素并且 for-each-group 中的 &lt;xsl:copy-of select="."/&gt; 输出第一个每个组,无论它是否只有一个元素或更多元素都无关紧要。
    • 所以如果我需要一个条件,比如说有 2 个相同的数字对象,并且我想检查状态 Y,你的逻辑是否有效,如果我需要另一个条件,说它是否在组中的 1 个数字对象但我不想检查状态 y,请问我该怎么做?
    • for-each-group 内部调用current-group() 会为您提供当前组中的一系列项目,因此您可以检查count(current-group()) gt 1 以检查组中是否有多个项目和count(current-group()) eq 1not(current-group()[2]) 检查组中是否只有一项。如果您还有其他问题,请考虑提出一个包含详细信息的新问题。
    • 谢谢 Mrtin,我确实发布了一个新问题 stackoverflow.com/questions/20055425/… 。你能帮我解决这个问题吗
    猜你喜欢
    • 2018-12-18
    • 1970-01-01
    • 2019-08-10
    • 1970-01-01
    • 2022-10-04
    • 1970-01-01
    • 2011-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多