I want to create nested XML nodes using a single node from an XML structure, I tried but unable to bring the nested XML structure, Can some please help me, I am unable to get the expected behavior.
XML Sructure:
<job[n]/> -> 0...n
<person-non-active/> -> 1
<removed> -> 1
<?xml version="1.0" encoding="UTF-8"?>
<root>
<person>
<job1/>
<job2/>
<person-non-active>
<removed>
<job3/>
<job4/>
</removed>
</person-non-active>
</person>
<person>
<bio>
<job1/>
<job2/>
<person-non-active>
<removed>
<job3/>
</removed>
</person-non-active>
</bio>
</person>
<person>
<person-non-active>
<removed>
<job3/>
<job4/>
</removed>
</person-non-active>
</person>
</root>
XSL Used:
<xsl:template match="person-non-active">
<person>
<xsl:if test="(count(../*) > 1)">
<job>
<xsl:attribute name="status"><xsl:text>active</xsl:text></xsl:attribute>
<xsl:attribute name="jobs">
<xsl:for-each select="../*">
<xsl:if test="not(name() = 'person-non-active')">
<xsl:value-of select="name()"/><xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:attribute>
</job>
</xsl:if>
<xsl:if test="(count(./removed/*) > 0)">
<job>
<xsl:attribute name="status"><xsl:text>non-acitve</xsl:text></xsl:attribute>
<xsl:attribute name="jobs">
<xsl:for-each select="./removed/*">
<xsl:value-of select="name()"/><xsl:text>, </xsl:text>
</xsl:for-each>
</xsl:attribute>
</job>
</xsl:if>
</person>
</xsl:template>
Output Received:
<person>
<job status="active" jobs="job1, job2, "/>
<job status="non-acitve" jobs="job3, job4, "/>
</person>
Expected Output
<person>
<job status="active" jobs="job1, job2, ">
<job status="non-acitve" jobs="job3, job4, "/>
</job>
</person>
<person>
<bio>
<job status="active" jobs="job1, job2, ">
<job status="non-acitve" jobs="job3, "/>
</job>
</bio>
</person>
<person>
<job status="non-acitve" jobs="job3, job4, "/>
</person>
"person-non-active" element should be used for match