Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...