Usecase:
Here, we will demonstrate how we can fetch unique comma separeated values for a xml field values.
For instance , here
Input file:
<Root>
<qualification_code>A</qualification_code>
<qualification_code>B</qualification_code>
<qualification_code>A</qualification_code>
<qualification_code>C</qualification_code>
<qualification_code>B</qualification_code>
</Root>
Expected Output:
"A", "B", "C"
Solution:
Implementation steps:
- Use distinct-values() function to get the distinct node values.
- For each record, take the values using select ="."
- Using text field to hard codes like quotes or comma and space
- Use position() != last() condition to avoid the last comma.
xslt code:
<xsl:template match="/" xml:id="id_11">
<nstrgmpr:Write xml:id="id_12">
<ns22:RecordSet xml:id="id_31">
<ns22:Record xml:id="id_32">
<ns22:Test xml:id="id_36">
<xsl:for-each xml:id="id_35" select="distinct-values($readFile/nsmpr2:ReadResponse/ns25:RecordSet/ns25:Record/ns25:QUALIFICATION_CODE)">
<xsl:text>"</xsl:text>
<xsl:value-of xml:id="id_37" select="."/>
<xsl:text>"</xsl:text>
<xsl:text>,</xsl:text>
<xsl:if test="position() != last()">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
</ns22:Test>
</ns22:Record>
</ns22:RecordSet>
</nstrgmpr:Write>
</xsl:template>
Screenshot:
No comments:
Post a Comment