I have a requirement to find duplicate and empty nodes instead of removing them from the XML, so i wrote below XSL and am able to get the list of empty nodes by reading the XML.But am not able to get the result if Duplicate node exists. need your help to achieve this.
below is the input XML:
<p:Organisation xmlns:p="http://www.tibco.com/schemas/prjDelimeter/Schema/Schema2.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.tibco.com/schemas/prjDelimeter/Schema/Schema2.xsd HeaderRecords.xsd ">
<p:EMP>
<p:ID>123</p:ID>
<p:Name>uday</p:Name>
<p:Designation>SoftwareEng</p:Designation>
<p:ExpertiseIn>SOA,OSB,TIBCO</p:ExpertiseIn>
</p:EMP>
<p:ASSETS>
<p:ASSET>
<p:AssetID>1000</p:AssetID>
<p:Name>Ego</p:Name>
<p:InUse>yes</p:InUse>
<p:AssignedDate>2005</p:AssignedDate>
</p:ASSET>
<p:ASSET>
<p:AssetID>2000</p:AssetID>
<p:Name>HP</p:Name>
<p:InUse></p:InUse>
<p:AssignedDate>2002</p:AssignedDate>
</p:ASSET>
<p:ASSET>
<p:AssetID>3000</p:AssetID>
<p:Name>Dell</p:Name>
<p:InUse>yes</p:InUse>
<p:AssignedDate>2010</p:AssignedDate>
</p:ASSET>
<p:ASSET>
<p:AssetID>4000</p:AssetID>
<p:Name></p:Name>
<p:InUse>yes</p:InUse>
<p:AssignedDate>2009</p:AssignedDate>
</p:ASSET>
<p:ASSET>
<p:AssetID>3000</p:AssetID>
<p:Name>Lenovo</p:Name>
<p:InUse>yes</p:InUse>
<p:AssignedDate>2011</p:AssignedDate>
</p:ASSET>
</p:ASSETS>
</p:Organisation>
and below is the current output i get if i see any empty nodes:
InUse in Line- 2 with Position-3 is empty
Name in Line- 4 with Position-2 is empty
below is the expected Output :
InUse in Line- 2 with Position-3 is empty
Name in Line- 4 with Position-2 is empty
Found Duplicate Asset ID's
below is the XSLT that i have worked and able to get till list of empty nodes:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:p="http://www.tibco.com/schemas/prjDelimeter/Schema/Schema2.xsd">
<xsl:output omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:apply-templates mode="rule1"
select="p:Organisation/p:EMP/p:ID">
</xsl:apply-templates>
<xsl:apply-templates mode="rule2"
select="p:Organisation/p:EMP/p:Name">
</xsl:apply-templates>
<xsl:apply-templates mode="rule3"
select="p:Organisation/p:EMP/p:Designation">
</xsl:apply-templates>
<xsl:apply-templates mode="rule4"
select="p:Organisation/p:EMP/p:ExpertiseIn">
</xsl:apply-templates>
<xsl:apply-templates mode="rule5"
select="p:Organisation/p:ASSETS">
</xsl:apply-templates>
</xsl:template>
<!-- Employee data Validation -->
<xsl:template match="p:ID" mode="rule1">
<xsl:if test="current() = ''">
Employee ID is empty.
</xsl:if>
</xsl:template>
<xsl:template match="p:Name" mode="rule2">
<xsl:if test="current() = ''">
Employee Name is empty.
</xsl:if>
</xsl:template>
<xsl:template match="p:Designation" mode="rule3">
<xsl:if test="current() = ''">
Employee Designation is empty.
</xsl:if>
</xsl:template>
<xsl:template match="p:ExpertiseIn" mode="rule4">
<xsl:if test="current() = ''">
ExpertiseIn data can't be empty.
</xsl:if>
</xsl:template>
<!-- Assets data Validation -->
<xsl:template match="p:ASSETS/*" mode='rule5'>
<xsl:variable name="i" select="count(preceding-sibling::*)+1" />
<xsl:for-each select="child::*">
<xsl:if test="current() = '' ">
<xsl:value-of select="local-name()" /> in Line- <xsl:value-of select="$i" /> with Position-<xsl:value-of select="count(preceding-sibling::*)+1" /> is empty
</xsl:if>
</xsl:for-each>
</xsl:template>
please help me in finding duplicate nodes too.
Thanks for your helping hands.