I am NOT familiar with XSL and need some help from you experts.
Try to only convert
<RiskType>Risk1, Risk2, Risk3</RiskType>
To
<RiskType>Risk1</RiskType>
<RiskType>Risk2</RiskType>
<RiskType>Risk3</RiskType>
But I have to keep everything else intact. Based on other articles, I tried to use XSL, but it seems to do the above but destroy the structure and other tags.
<Policy>
<PolNumber>123456789</PolNumber>
<LineOfBusiness tc="1">Life</LineOfBusiness>
<Life>
<Coverage id="">
<LifeCovTypeCode tc="123">Child Term Rider</LifeCovTypeCode>
<NumChildren>2</NumChildren>
</Coverage>
<PlanName>MyPlan</PlanName>
</Life>
<ApplicationInfo>
<OLifeEExtension>
<RiskTypes>
<RiskType>Risk1, Risk2, Risk3</RiskType>
</RiskTypes>
</OLifeEExtension>
</ApplicationInfo>
</Policy>
To
<Policy>
<PolNumber>123456789</PolNumber>
<LineOfBusiness tc="1">Life</LineOfBusiness>
<Life>
<Coverage id="">
<LifeCovTypeCode tc="123">Child Term Rider</LifeCovTypeCode>
<NumChildren>2</NumChildren>
</Coverage>
<PlanName>MyPlan</PlanName>
</Life>
<ApplicationInfo>
<OLifeEExtension>
<RiskTypes>
<RiskType>Risk1</RiskType>
<RiskType>Risk2</RiskType>
<RiskType>Risk3</RiskType>
</RiskTypes>
</OLifeEExtension>
</ApplicationInfo>
</Policy>
XSL does not work
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Main template -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="tokenize-children" />
</xsl:copy>
</xsl:template>
<!-- Split child nodes -->
<xsl:template match="*" mode="tokenize-children">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="*" mode="tokenize" />
</xsl:copy>
</xsl:template>
<!-- Tokenize text node of child nodes -->
<xsl:template match="*/text()" name="tokenize" mode="tokenize">
<xsl:param name="text" select="."/>
<xsl:param name="separator" select="','"/>
<xsl:variable name="item" select="name(..)" />
<xsl:choose>
<xsl:when test="not(contains($text, $separator))">
<xsl:element name="{$item}">
<xsl:value-of select="normalize-space($text)"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{$item}">
<xsl:value-of select="normalize-space(substring-before($text, $separator))"/>
</xsl:element>
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="substring-after($text, $separator)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
I'd suggest you try it this way:
XSLT 1.0
Or, if you prefer: