I have an XML as below:
<Main>
<rFs>
<rF>
<iT>T</iT>
<ref>F1</ref>
<recs>
<rec>
<iT>T</iT>
<ref>T0</ref>
<cT Code="R" Des="Regular">R</cT>
<fT Code="N" Description="National">N</fT>
<st Code="D" Description="Dock">D</st>
</rec>
<rec>
<iT>T</iT>
<ref>T0</ref>
<cT Code="R" Description="Regular">R</cT>
<fT Code="Q" Description="Mad">Q</fT>
</rec>
</recs>
</rF>
<rF>
<iT>T</iT>
<ref>F2</ref>
<recs>
<rec>
<iT>T</iT>
<ref>T1</ref>
<cT Code="S" Des="Regular">R</cT>
<fT Code="N" Description="Inter">I</fT>
</rec>
<rec>
<iT>T</iT>
<ref>T1</ref>
<cT Code="S" Description="Time">R</cT>
<fT Code="Q" Description="Mad">Q</fT>
</rec>
</recs>
</rF>
</rFs>
</Main>
There is already an XSLT according to the requirements. The XSLT is as follows:
<xsl:template match="Main">
<rFs>
<xsl:for-each select="rFs/rF[iT = 'T']">
<rF>
<xsl:attribute name="id">
<xsl:value-of select="concat(ref,'_','fam')"/>
</xsl:attribute>
<recs>
<xsl:for-each-group select="recs/rec" group-by="ref">
<xsl:for-each select="current-group()">
<rec>
<xsl:attribute name="id">
<xsl:value-of select="ref"/>
</xsl:attribute>
<st>
<xsl:value-of select="st/@Code"/>
</st>
</rec>
</xsl:for-each>
</xsl:for-each-group>
</recs>
</rF>
</xsl:for-each>
</rFs>
</xsl:template>
The above XSLT gives the following XML as output -
<rFs>
<rF id="F1_fam">
<recs>
<rec id="T0">
<st>D</st>
</rec>
<rec id="T0">
<st/>
</rec>
</recs>
</rF>
<rF id="F2_fam">
<recs>
<rec id="T1">
<st/>
</rec>
<rec id="T1">
<st/>
</rec>
</recs>
</rF>
</rFs>
Now I have to make updations in the above XSLT.
My requirements are:
-
- remove
<rec>where<st>is null
- remove
-
- If all the
<rec>under<rf>have<st>as null, then remove the entire<rf>
- If all the
The implementation of the above requirements should generate the Final XML as:
<rFs>
<rF id="F1_fam">
<recs>
<rec id="T0">
<st>D</st>
</rec>
</recs>
</rF>
</rFs>
I have gone through many post regarding the same but nothing seems to work.