My XML code displays all the address of an employee and its usage type. The address must be display only if it has specific usage type. The others must be removed.
Below is the xml.
`<peci:Person_Communication>
<peci:Address>
<peci:Usage_Type>HOME1</peci:Usage_Type>
<peci:Address_Line_1>Gen. Sochora</peci:Address_Line_1>
<peci:Address_Line_3>31</peci:Address_Line_3>
<peci:Address_Line_4>957</peci:Address_Line_4>
<peci:City>Třebíč</peci:City>
<peci:Postal_Code>674 01</peci:Postal_Code>
<peci:Country>CZ</peci:Country>
<peci:Usage>
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-6</peci:Usage_Behavior_ID>
</peci:Usage>
</peci:Address>
<peci:Address>
<peci:Usage_Type>HOME2</peci:Usage_Type>
<peci:Address_Line_1>Gen. Sochora</peci:Address_Line_1>
<peci:Address_Line_3>31</peci:Address_Line_3>
<peci:Address_Line_4>957</peci:Address_Line_4>
<peci:City>Třebíč</peci:City>
<peci:Postal_Code>674 01</peci:Postal_Code>
<peci:Country>CZ</peci:Country>
<peci:Usage>
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-16</peci:Usage_Behavior_ID>
</peci:Usage>
<peci:Usage>
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-1</peci:Usage_Behavior_ID>
</peci:Usage>
</peci:Address>
<peci:Address>
<peci:Usage_Type>HOME3</peci:Usage_Type>
<peci:Address_Line_1>Gen. Sochora</peci:Address_Line_1>
<peci:Address_Line_3>31</peci:Address_Line_3>
<peci:Address_Line_4>957</peci:Address_Line_4>
<peci:City>Třebíč</peci:City>
<peci:Postal_Code>674 01</peci:Postal_Code>
<peci:Country>CZ</peci:Country>
<peci:Usage>
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-8</peci:Usage_Behavior_ID>
</peci:Usage>
<peci:Usage>
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-9</peci:Usage_Behavior_ID>
</peci:Usage>
</peci:Address>
<peci:Address>
<peci:Usage_Type>HOME4</peci:Usage_Type>
<peci:Address_Line_1>Gen. Sochora</peci:Address_Line_1>
<peci:Address_Line_3>31</peci:Address_Line_3>
<peci:Address_Line_4>957</peci:Address_Line_4>
<peci:City>Třebíč</peci:City>
<peci:Postal_Code>674 01</peci:Postal_Code>
<peci:Country>CZ</peci:Country>
<peci:Usage>
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-1</peci:Usage_Behavior_ID>
</peci:Usage>
<peci:Usage>
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-9</peci:Usage_Behavior_ID>
</peci:Usage>
</peci:Address>
<peci:Address>
<peci:Usage_Type>HOME5</peci:Usage_Type>
<peci:Address_Line_1>Gen. Sochora</peci:Address_Line_1>
<peci:Address_Line_3>31</peci:Address_Line_3>
<peci:Address_Line_4>957</peci:Address_Line_4>
<peci:City>Třebíč</peci:City>
<peci:Postal_Code>674 01</peci:Postal_Code>
<peci:Country>CZ</peci:Country>
</peci:Address>
<peci:Address>
<peci:Usage_Type>HOME6</peci:Usage_Type>
<peci:Address_Line_1>Gen. Sochora</peci:Address_Line_1>
<peci:Address_Line_3>31</peci:Address_Line_3>
<peci:Address_Line_4>957</peci:Address_Line_4>
<peci:City>Třebíč</peci:City>
<peci:Postal_Code>674 01</peci:Postal_Code>
<peci:Country>CZ</peci:Country>
<peci:Usage>
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-10</peci:Usage_Behavior_ID>
</peci:Usage>
<peci:Usage>
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-8</peci:Usage_Behavior_ID>
</peci:Usage>
<peci:Usage>
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-6</peci:Usage_Behavior_ID>
</peci:Usage>
<peci:Usage>
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-1</peci:Usage_Behavior_ID>
</peci:Usage>
</peci:Address>
</peci:Person_Communication>`
Address’s that only contains ‘COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-1’ , ‘COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-16’ and ‘COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-6’ and Address that do not have Usage element must be displayed. rest has be removed.
Below is the logic I have written in the XSLT code.
` <xsl:template match="peci:Person_Communication/peci:Address">
<xsl:variable name="AddUsage1" select="peci:Usage/peci:Usage_Behavior_ID[.='COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-16' or .='COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-6' or .='COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-1']"/>
<xsl:variable name="AddUsage2" select="peci:Usage/peci:Usage_Behavior_ID[.='COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-9' or .='COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-8' or .='COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-10' or .='COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-11' or .='COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-12' or .='COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-13']"/>
<xsl:choose>
<xsl:when test="$AddUsage1 and not($AddUsage2)">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:when test="$AddUsage1 and $AddUsage2">
<xsl:copy-of select="peci:Usage_Type|peci:Address_Line_1|peci:Address_Line_3|peci:Address_Line_4|peci:City|peci:Postal_Code|peci:Country|peci:Country_Region"/>
<peci:Usage>
<xsl:copy-of select="$AddUsage1"/>
</peci:Usage>
</xsl:when>
<xsl:when test="not($AddUsage1) and not($AddUsage2)">
<xsl:copy-of select="."/>
</xsl:when>
</xsl:choose>
</xsl:template>`
And below is the output.
`<peci:Person_Communication>
<peci:Address>
<peci:Usage_Type>HOME1</peci:Usage_Type>
<peci:Address_Line_1>Gen. Sochora</peci:Address_Line_1>
<peci:Address_Line_3>31</peci:Address_Line_3>
<peci:Address_Line_4>957</peci:Address_Line_4>
<peci:City>Treb�/peci:City>
<peci:Postal_Code>674 01</peci:Postal_Code>
<peci:Country>CZ</peci:Country>
<peci:Usage>
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-6</peci:Usage_Behavior_ID>
</peci:Usage>
</peci:Address>
<peci:Address>
<peci:Usage_Type>HOME2</peci:Usage_Type>
<peci:Address_Line_1>Gen. Sochora</peci:Address_Line_1>
<peci:Address_Line_3>31</peci:Address_Line_3>
<peci:Address_Line_4>957</peci:Address_Line_4>
<peci:City>Treb�/peci:City>
<peci:Postal_Code>674 01</peci:Postal_Code>
<peci:Country>CZ</peci:Country>
<peci:Usage>
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-16</peci:Usage_Behavior_ID>
</peci:Usage>
<peci:Usage>
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-1</peci:Usage_Behavior_ID>
</peci:Usage>
</peci:Address>
<peci:Usage_Type>HOME4</peci:Usage_Type>
<peci:Address_Line_1>Gen. Sochora</peci:Address_Line_1>
<peci:Address_Line_3>31</peci:Address_Line_3>
<peci:Address_Line_4>957</peci:Address_Line_4>
<peci:City>Treb�/peci:City>
<peci:Postal_Code>674 01</peci:Postal_Code>
<peci:Country>CZ</peci:Country>
<peci:Usage xmlns:ptdf="urn:com.workday/peci/tdf">
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-1</peci:Usage_Behavior_ID>
</peci:Usage>
<peci:Address>
<peci:Usage_Type>HOME5</peci:Usage_Type>
<peci:Address_Line_1>Gen. Sochora</peci:Address_Line_1>
<peci:Address_Line_3>31</peci:Address_Line_3>
<peci:Address_Line_4>957</peci:Address_Line_4>
<peci:City>Treb�/peci:City>
<peci:Postal_Code>674 01</peci:Postal_Code>
<peci:Country>CZ</peci:Country>
</peci:Address>
<peci:Usage_Type>HOME6</peci:Usage_Type>
<peci:Address_Line_1>Gen. Sochora</peci:Address_Line_1>
<peci:Address_Line_3>31</peci:Address_Line_3>
<peci:Address_Line_4>957</peci:Address_Line_4>
<peci:City>Treb�/peci:City>
<peci:Postal_Code>674 01</peci:Postal_Code>
<peci:Country>CZ</peci:Country>
<peci:Usage xmlns:ptdf="urn:com.workday/peci/tdf">
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-6</peci:Usage_Behavior_ID>
<peci:Usage_Behavior_ID>COMMUNICATION_USAGE_BEHAVIOR_TENANTED-3-1</peci:Usage_Behavior_ID>
</peci:Usage>
</peci:Person_Communication>`
for the cases where both Variables $AddUsage1 and $AddUsage2 are present the element peci:Address/ is missing and all values for Usage behaviour are placed under a single peci:Usage instead of separate elements. Please help me fix the below logic.
`<xsl:when test="$AddUsage1 and $AddUsage2">
<xsl:copy-of select="peci:Usage_Type|peci:Address_Line_1|peci:Address_Line_3|peci:Address_Line_4|peci:City|peci:Postal_Code|peci:Country|peci:Country_Region"/>
<peci:Usage>
<xsl:copy-of select="$AddUsage1"/>
</peci:Usage>
</xsl:when>`