Requirement-"The stylesheet should be modified not to add DUCK(product type) if there exists one with the same action(product action)".
ie how can i write validation in XSLT to add a DUCK if and only if the product action is different. In the xml given below the action of two products is "Add". For the stylesheet sholud not add DUCK

The XSLT is
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:invoker="http://xml.apache.org/xalan/java/vf.bis.xsltc.ServiceInvoker" exclude-result-prefixes="xs xsi invoker">
<xsl:output method="xml" omit-xml-declaration="yes" encoding="iso-8859-1" indent="yes" />
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="product[count(./GetInfoOutput)>0]">

<!-- DUCK product
-->
<xsl:if test="count(./GetInfoOutput/lovRecords[key1='DUCK'])>0">
<xsl:element name="product">
<xsl:attribute name="id">
<xsl:value-of disable-output-escaping="yes" select="invoker:GenerateUUID()" />
</xsl:attribute>
<xsl:attribute name="parentId">
<xsl:value-of select="./@parentId" />
</xsl:attribute>
<xsl:attribute name="customerId">
<xsl:value-of select="./@customerId" />
</xsl:attribute>
<xsl:attribute name="type">
<xsl:value-of select="./GetInfoOutput/lovRecords[key1='DUCK']/key1" />
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="./GetInfoOutput/lovRecords[key1='DUCK']/key3" />
</xsl:attribute>
<xsl:attribute name="provider">
<xsl:value-of select="./GetInfoOutput/lovRecords[key1='DUCK']/lovSystem" />
</xsl:attribute>
<xsl:element name="parameter">
<xsl:attribute name="name">Product Category</xsl:attribute>
<xsl:value-of select="./GetInfoOutput/lovRecords[key1='DUCK']/description" />
</xsl:element>
<xsl:element name="parameter">
<xsl:attribute name="name">Product Type</xsl:attribute>
<xsl:value-of select="./GetInfoOutput/lovRecords[key1='DUCK']/key1" />
</xsl:element>
<xsl:element name="parameter">
<xsl:attribute name="name">Network Command</xsl:attribute>
<xsl:value-of select="./GetInfoOutput/lovRecords[key1='DUCK']/value1" />
</xsl:element>
<xsl:element name="action">
<xsl:attribute name="name">
<xsl:value-of select="./action/@name" />
</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

The XML looks like this
<?xml version="1.0"?>
<order id="V123-0" name="Management" type="Transfer" date="2008-11-25T15:18:39" sourceSystem="pjs" sourceSystemId="AGS05026112" sourceSystemUser="Z" operator="Z">
<customer id="wer65537">
<identifiers system="S">
<identifier name="Stud-id">123</identifier>
</identifiers>
<characteristic name="something">kg</characteristic>
</customer>
<product id="5f70b6174cafbaf411d63" parentId="N661" customerId="wer65537" type="something" name="DUCK" provider="Z">
<parameter name="Externa">DTC</parameter>
<parameter name="Command">DTC</parameter>
</product>
<product id="6cfc676b44390bd011d6" parentId="N655" customerId="wer65537" name="asdf" provider="NE" type="DUCK">
<parameter name="Pro Cat">Cat</parameter>
<parameter name="Pro Ty">DUCK</parameter>
<parameter name="Net Comm">DT</parameter>
<action name="Add"/>
</product>
<product id="6cfc676b44390bd011d6352" parentId="N661" customerId="wer5537" name="asdf" provider="NE" type="DUCK">
<parameter name="Pro Cat">Ser Con</parameter>
<parameter name="Product Type">DUCK</parameter>
<parameter name="Net Com">Net Com</parameter>
<action name="Add"/>
</product>
</order>

precedent sibling could do the work :)


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:invoker="http://xml.apache.org/xalan/java/vf.bis.xsltc.ServiceInvoker" exclude-result-prefixes="xs xsi invoker">
<xsl:output method="xml" omit-xml-declaration="yes" encoding="iso-8859-1" indent="yes" />
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>


<xsl:template match="product">

<xsl:if test="not ( (preceding-sibling::*/@name) = @name)">

<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>


</xsl:if>

</xsl:template>

</xsl:stylesheet>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.