I have an XSL file that transforms the same data from one XML format to another. I am having trouble with one aspect of it though... If two of the <Attributes ID=""></Attributes> nodes have the same ID value then I need to present them as one Node in the new format. Pay particular attential to the nodes where id=14.
The logic is that in the old format, if the <Value> node has an id of -6 then there may be a corresponding <Attributes> node (with the same ID value) that contains a <ValueLiteral> node with a string that, in the new version needs to be placed in the same <Attributes> node instead of having two <Attributes> nodes with the same ID.
Any help Getting this XSL working properly will be greatly appreciated.
Here is my XSL:
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
----
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="
http://www.w3.org/1999/XSL/Transform" version="1.0" >
<xsl:template match="/">
<Attributes>
<xsl:for-each select="//AttributeSet" >
<AttributeSet>
<xsl:attribute name="id">
<xsl:value-of select="@id" />
</xsl:attribute>
<xsl:for-each select="Attribute" >
<Attribute>
<xsl:attribute name="id">
<xsl:value-of select="@id" />
</xsl:attribute>
<ValueList>
<xsl:for-each select="Value" >
<Value>
<xsl:choose>
<xsl:when test="@id">
<xsl:attribute name="id">
<xsl:value-of select="@id" />
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<ValueLiteral>
<xsl:value-of select="Name" />
</ValueLiteral>
</xsl:otherwise>
</xsl:choose>
</Value>
</xsl:for-each>
</ValueList>
</Attribute>
</xsl:for-each>
</AttributeSet>
</xsl:for-each>
</Attributes>
</xsl:template>
</xsl:stylesheet>
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
-
Here is my original XML that I need to apply the XSL to:
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
----
<?xml version="1.0" encoding="UTF-8" ?>
<SelectedAttributes>
<AttributeSet id="1951">
<Attribute id="6">
<Value id="31246" />
</Attribute>
<Attribute id="31245">
<Value id="31253" />
</Attribute>
<Attribute id="26446">
<Value>
<Name>13</Name>
</Value>
</Attribute>
<Attribute id="14">
<Value id="-6" />
</Attribute>
<Attribute id="14">
<Value>
<Name>BRAND NAME</Name>
</Value>
</Attribute>
<Attribute id="31243">
<Value id="31279" />
</Attribute>
<Attribute id="10244">
<Value id="-10" />
</Attribute>
</AttributeSet>
</SelectedAttributes>
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
-----
Here is the output I am currently getting:
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
-----
<?xml version="1.0" encoding="UTF-8"?>
<Attributes>
<AttributeSet id="1951">
<Attribute id="6">
<ValueList>
<Value id="31246"/>
</ValueList>
</Attribute>
<Attribute id="31245">
<ValueList>
<Value id="31253"/>
</ValueList>
</Attribute>
<Attribute id="26446">
<ValueList>
<Value>
<ValueLiteral>13</ValueLit
eral>
</Value>
</ValueList>
</Attribute>
<Attribute id="14">
<ValueList>
<Value id="-6"/>
</ValueList>
</Attribute>
<Attribute id="14">
<ValueList>
<Value>
<ValueLiteral>BRAND NAME</ValueLiteral>
</Value>
</ValueList>
</Attribute>
<Attribute id="31243">
<ValueList>
<Value id="31279"/>
</ValueList>
</Attribute>
<Attribute id="10244">
<ValueList>
<Value id="-10"/>
</ValueList>
</Attribute>
</AttributeSet>
</Attributes>
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
-----
Here is the output I want:
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
-----
<?xml version="1.0" encoding="UTF-8" ?>
<Attributes>
<AttributeSet id="1951" categoryId="50604">
<Attribute id="31245">
<ValueList>
<Value id="31253" />
</ValueList>
</Attribute>
<Attribute id="31243">
<ValueList>
<Value id="31279" />
</ValueList>
</Attribute>
<Attribute id="10244">
<ValueList>
<Value id="-10" />
</ValueList>
</Attribute>
<Attribute id="6">
<ValueList>
<Value id="31246" />
</ValueList>
</Attribute>
<Attribute id="26446">
<ValueList>
<Value id="-3">
<ValueLiteral>13</ValueLit
eral>
</Value>
</ValueList>
</Attribute>
<Attribute id="14">
<ValueList>
<Value id="-6">
<ValueLiteral>BRAND NAME</ValueLiteral>
</Value>
</ValueList>
</Attribute>
</AttributeSet>
</Attributes>