I need to analyse the following XML input:
<LIST>
<PRODUCT TYPE="1" REP="0">
<SUB CAT="1.1" COUNT="2">
<ITEM NAME="OCC" BEGIN="0" ND="49">
</ITEM>
<ITEM NAME="OCC" BEGIN="0" END="49">
</ITEM>
</SUB>
</PRODUCT>
<PRODUCT TYPE="1" REP="1">
<SUB CAT="1.1" COUNT="1">
<ITEM NAME="PRC" BEGIN="0" END="49">
</ITEM>
</SUB>
</PRODUCT>
</LIST>
and transform it with Xslt to obtain the following result:
<LIST>
<PRODUCT TYPE="1" REP="0">
<SUB CAT="1.1" COUNT="2">
<MULTIPLE />
<ITEM NAME="OCC" BEGIN="0" END="49">
</ITEM>
<MULTIPLE />
<ITEM NAME="OCC" BEGIN="0" END="49">
</ITEM>
</SUB>
</PRODUCT>
<PRODUCT TYPE="1" REP="1">
<SUB CAT="1.1" COUNT="1">
<MULTIPLE />
<ITEM NAME="PRC" BEGIN="0" END="49">
</ITEM>
</SUB>
</PRODUCT>
</LIST>
What I need to do is to check that the BEGIN and END of the ITEMS in two different PRODUCT node are the same, and if this is the case add the MULTIPLE node as a flag. Any idea on how to proceed? This is how I thought it could work:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="//PRODUCT[@TYPE='1']/SUB[@CAT='1.1']/ITEM">
<xsl:if test="//PRODUCT[@TYPE='1']/SUB[@CAT='1.1']/ITEM /RULE (@BEGIN <= current()/@BEGIN) and (@END >= current()/@END)]">
<xsl:element name="MULTIPLE">
</xsl:element>
</xsl:if>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
This can be achieved by means of a key to look up
ITEM
elementsThen, you just need a template that matches
ITEM
elements where there is at least 2 items in the keyUsing this in conjunction with the XSLT identity transform, gives you this XSLT
If you wish to restrict it to look for matches in the same product and sub-category, change the key to this...
And adjust the template match accordingly....
You can try like this way by match the ITEM context: