Help Needed to write the correct XSLT
Xml structure like below:
<NonSession>
<Items>
<Item>
<Code>A</Code>
<Description>Desc<Description>
</Item>
<Item>
<Code>B</Code>
<Description>Desc<Description>
</Item>
<Item>
<Code>C</Code>
<Description>Test<Description>
</Item>
<Item>
<Code>A</Code>
<Description>Desc<Description>
</Item>
<Items>
</NonSession>
XSlt like below:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<Errors>
<xsl:apply-templates select="NonSession//Items"/>
</Errors>
<xsl:template match="NonSession//Items">
<xsl:if test="((Item//Code = 'A' or //Item//Code = 'B') and not(Item//Description = 'Desc'))" >
<Error>
<xsl:for-each select="Item">
<XPath>
<xsl:text>/</xsl:text>
<xsl:for-each select="ancestor-or-self::*">
<xsl:value-of select="name()"/>
<xsl:text>/</xsl:text>
</xsl:for-each>
<xsl:text>Desc</xsl:text>
</XPath>
</xsl:for-each>
</Error>
</xsl:if>
</xsl:template>
The final ouput should be something like :
<Errors>
<Error>
All the xpaths of the nodes where ((Code = A or B) and Description != Desc)
<Error>
</Errors>
The if condition in the template is not giving me the exact nodes. Any help would be much appreciated.
|