I am trying to remove duplicate number after tokenize the value and another entry value e.g. <p>1(a), (b), (c)</p>
and <p>1(a)</p>
. How to remove duplicate entry using group-by.
Input XML
<root>
<p>1(a), (b), (c)</p>
<p>1(a)</p>
<p>2(a)</p>
<p>3(a)</p>
<p>1(c)</p>
</root>
Expected Output
<root>
<p>1(a)</p>
<p>1(b)</p>
<p>1(c)</p>
<p>2(a)</p>
<p>3(a)</p>
</root>
XSLT Code
<xsl:template match="root">
<root>
<xsl:for-each-group select="p" group-by=".">
<xsl:sort select="current-grouping-key()" data-type="number" order="ascending"/>
<xsl:choose>
<xsl:when test="contains(current-grouping-key(), ', ')">
<xsl:variable name="tokens" select="tokenize(current-grouping-key(), ', and |, ')"/>
<xsl:for-each select="$tokens">
<p>
<xsl:value-of
select="if (starts-with(., '('))
then replace(head($tokens), '(.*)(.*?)$', '$1') || .
else ."/>
</p>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<p><xsl:value-of select="current-grouping-key()"/></p>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</root>
</xsl:template>
question from:
https://stackoverflow.com/questions/65879616/how-to-remove-same-number-after-tokenize-use-group-by-in-xslt 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…