Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

xml - Need to remove the plan value for multiple condition

I need to remove the plan options for the same multiple value occurrence

test.xml

<p base="OptionDesc"></p>

Input XML value having:

<PlanMaps>
    <PlanMap>
        <PlanCode>10049</PlanCode>
        <Strategy>F</Strategy>
        <OptionDesc>Option 2424809</OptionDesc>
    </PlanMap>
    <PlanMap>
        <PlanCode>10049</PlanCode>
        <Strategy>F</Strategy>
        <OptionDesc>Option 2424796</OptionDesc>
    </PlanMap>
    <PlanMap>
        <PlanCode>10049</PlanCode>
        <Strategy>F</Strategy>
        <OptionDesc>Option 2414596</OptionDesc>
    </PlanMap>
    <PlanMap>
        <PlanCode>30019</PlanCode>
        <Strategy>V</Strategy>
        <OptionDesc>Option 2414600</OptionDesc>
    </PlanMap>
  </PlanMaps>

XSL I have tried:

<xsl:template match="PlanMaps">
      <xsl:apply-templates select="document('../../../../test.xml')"/>
   </xsl:template>  
   
<xsl:template match="p[@base='OptionDesc'][parent::entry/@outputclass='plans']">
    <p base="OptionDesc">
        <xsl:text>(</xsl:text>
        <xsl:value-of select="PlanMaps/PlanMap/OptionDesc"/>    
        <xsl:text>)</xsl:text>
    </p>
</xsl:template>

Expectation of result when the Strategy value is "F" and when PlanCode value (10049) is same for multiple occurrence(two or more), then result should be empty like below

<p base="OptionDesc"></p>
<p base="OptionDesc">(Option 2414600)</p>

Here I need the XSL without mentioning the value of plancode in XSL.

question from:https://stackoverflow.com/questions/65937765/need-to-remove-the-plan-value-for-multiple-condition

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It seems you just need to process the primary input:

  <xsl:template match="PlanMaps">
      <xsl:for-each-group select="PlanMap" group-by="concat(PlanCode, '|',  Strategy = 'F')">
          <p base="OptionDesc">
              <xsl:value-of select="concat('(', OptionDesc, ')')[not(current-group()[2] and current-group()/Strategy = 'F')]"/>
          </p>
      </xsl:for-each-group>
  </xsl:template>

https://xsltfiddle.liberty-development.net/bEJbVrN/1


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...