Interesting Error
Please go through the following cases .
-----------------------INPUT-------------------------------------
<mapping source="Case OK" action="M" [u]description="[+Action][+KeyList]" </u> enddate="2006/01/30">
<keylist>
<key name="fulfilledAtPointOfSale" value="Y"/>
</keylist>
</mapping>
<mapping source="Case I" [u]description="[-Action][+KeyList]"</u> enddate="2006/01/30">
<keylist>
<key name="fulfilledAtPointOfSale" value="Y"/>
</keylist>
</mapping>
<mapping source="Case II" [u]description="[-Action][-KeyList]"</u> enddate="2006/01/30">
<target product="T1234" suppliercode="Supp123" catalogid="Cat123">
<featuredefault name="Feature1" value="111"/>
</target>
</mapping>
------------------------OUTPUT----------------------------------
<mapping source="Case Ok" [u]description="[+Action][+KeyList]"</u> enddate="2006/01/30">
<keylist>
<key name="product.action" value="M"/>
<key name="fulfilledAtPointOfSale" value="Y"/>
</keylist>
</mapping>
<mapping source="Case I" description="[-Action][+KeyList]" enddate="2006/01/30">
<keylist>
<key name="product.action" value=""/>
<key name="fulfilledAtPointOfSale" value="Y"/>
</keylist>
</mapping>
<mapping source="Case II" description="[-Action][-KeyList]" enddate="2006/01/30">
<target product="T1234" suppliercode="Supp123" catalogid="Cat123">
<featuredefault name="Feature1" value="111"/>
</target>
</mapping>
-------------------------XSLT-------------------------------
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" media-type="text/xml"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="mapping">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:if test="@action">
<xsl:choose>
<xsl:when test="keylist">
<xsl:apply-templates select="mapping/keylist"/>
</xsl:when>
<xsl:otherwise>
<keylist>
<key name="product.action" value="{@action}"/>
</keylist>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:apply-templates select="*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="mapping/@action" />
<xsl:template match="mapping/keylist">
<xsl:copy>
<key name="product.action" value="{../@action}"/>
<xsl:apply-templates select="*"/>
</xsl:copy>
</xsl:template>
---------------------------------------------------------
Issues
1)I want to replace @action with <Keylist><key>...<key></keylist>
2)Transformation is as required in Case Ok
3)Case I , even if there is no @action the <key>..value=""</key> has been populated
4) Case II , the <keylist> is not added in this case as @action is missing
I have also copied the XSLT which is giving this effect
Help me finding the error in my XSLT. I m using XMLSPY for my transformation
Thanks in advance , awaiting your solutions.
Cheers
Kanchan
|