How to do for-each-group group-adjacent in XSLT 1.0 - xslt-1.0

Can someone help me convert the below XSLT 2.0 code to XSLT 1.0? Thanks.
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[E1EDL24]">
<xsl:copy>
<xsl:apply-templates select="#*"/>
<xsl:for-each-group select="node()" group-adjacent="boolean(self::E1EDL24)">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<xsl:apply-templates select="current-group()">
<xsl:sort select="MATNR" order="descending"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
</xsl:transform>

Try whether the following works:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="#*|node()" mode="sort">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:key name="adjacent-group" match="E1EDL24[preceding-sibling::*[1][self::E1EDL24]]" use="generate-id(preceding-sibling::E1EDL24[not(preceding-sibling::*[1][self::E1EDL24])][1])"/>
<xsl:template match="E1EDL24[not(preceding-sibling::*[1][self::E1EDL24])]">
<xsl:apply-templates select=". | key('adjacent-group', generate-id())" mode="sort">
<xsl:sort select="MATNR" order="descending"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="E1EDL24[preceding-sibling::*[1][self::E1EDL24]]"/>
</xsl:stylesheet>

Related

XSLT 1.0 Move of one Segment

please tell me, how can i move the Segment "BGM" from "CNT" to "GRP"?
Actually XML:
<?xml version="1.0"?>
<SEEDELFOR>
<AG/>
<CNT>
<TRANSMISSION_DATE>20190307</TRANSMISSION_DATE>
<TRANSMISSION_TIME>113300</TRANSMISSION_TIME> </INTERCHANGE_CONTROL_NUMBER>
</SENDER>
</SENDER_QUALIFIER>
</RECEIVER>
</RECEIVER_QUALIFIER>
</SYNTAX_IDENTIFIER>
</SYNTAX_VERSION>
<BGM>227</BGM>
<GRP>
</IDENTIFIER_BY>
</IDENTIFIER_SU>
</DATE_4>
</REF_ON>
</GRP>
</CNT>
</SEEDELFOR>
Correct output of my XML Should be:
<?xml version="1.0"?>
<SEEDELFOR>
<AG/>
<CNT>
<TRANSMISSION_DATE>20190307</TRANSMISSION_DATE>
<TRANSMISSION_TIME>113300</TRANSMISSION_TIME>
<SENDER></SENDER>
</SENDER_QUALIFIER>
</RECEIVER>
</RECEIVER_QUALIFIER>
</SYNTAX_IDENTIFIER>
</SYNTAX_VERSION>
<GRP>
<BGM>227</BGM>
</GRP>
</CNT>
</SEEDELFOR>
Here´s my XSLT: I tried to copy, but i think it´s better to move the segment?
Edit: Thats my full XSLT: Maybe i have to cominate with other copy segments?
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<!--Copy all of CNT != BGM-->
<xsl:template match="CNT">
<xsl:copy>
<xsl:apply-templates select="*[local-name()!='BGM']" />
</xsl:copy>
</xsl:template>
<!--copy BGM from CNT to GRP-->
<xsl:template match="GRP">
<xsl:element name="GRP">
<xsl:apply-templates />
<xsl:copy-of select="../BGM" />
</xsl:element>
</xsl:template>
<!--copy the data from ADD/CONTACT with Qualifier EM to GRP, so it can be used in the mapping to set EMAIL from Customer-->
<xsl:template match="GRP">
<xsl:copy>
<xsl:for-each select ="./ADD/CONTACT">
<xsl:if test="./QUALIFIER='EM'">
<CONTACT_EMAIL>
<xsl:value-of select="NUMBER"/>
</CONTACT_EMAIL>
</xsl:if>
<xsl:if test="./QUALIFIER='TE'">
<CONTACT_TEL>
<xsl:value-of select="NUMBER"/>
</CONTACT_TEL>
</xsl:if>
<xsl:if test="./QUALIFIER='FX'">
<CONTACT_FAX>
<xsl:value-of select="NUMBER"/>
</CONTACT_FAX>
</xsl:if>
</xsl:for-each>
<!--copy all other nodes-->
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<!--delete IC node-->
<xsl:template match="IC" />
<!--delete FILTER_SET node-->
<xsl:template match="FILTER_SET" />
<!--delete SEE_AG node-->
<xsl:template match="SEE_AG" />
<!--delete ME node-->
<xsl:template match="ME" />
<!--delete ADD node-->
<xsl:template match="ADD" />
<!-- delete segment (ADD) with specified QUALIFER (SU) -->
<xsl:template match="ADD[QUALIFIER='SU']"/>
<!--delete TRANSPORT_DETAILS node-->
<xsl:template match="TRANSPORT_DETAILS" />
<!--delete PACKAGE_DETAILS node-->
<xsl:template match="PACKAGE_DETAILS" />
<!--delete AMOUNT_DETAILS node-->
<xsl:template match="AMOUNT_DETAILS" />
<!--delete IC node-->
<xsl:template match="CONTACT" />
<!-- delete empty nodes -->
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[not(#*|*|comment()|processing-instruction()) and normalize-space()='']"/>
<!-- delete empty nodes -->
</xsl:stylesheet>
Thanks for your help.
Best regards
Julian
The idiomatic approach to "moving" a node from one place to another is:
copy everything as is,
except the node in question, and
copy the node to its new place:
XSLT 1.0
<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"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<!-- remove BGM -->
<xsl:template match="BGM"/>
<xsl:template match="GRP">
<xsl:copy>
<xsl:apply-templates/>
<!-- add BGM -->
<xsl:copy-of select="../BGM" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
If you need to modify other nodes, add templates matching them as necessary.
Seems your XML is not well formed. If I have got it right then you can find below xslt to achieve your requirement:
XML can be:
<?xml version="1.0"?>
<SEEDELFOR>
<AG />
<CNT>
<TRANSMISSION_DATE>20190307</TRANSMISSION_DATE>
<TRANSMISSION_TIME>113300</TRANSMISSION_TIME>
<INTERCHANGE_CONTROL_NUMBER />
<SENDER />
<SENDER_QUALIFIER />
<RECEIVER />
<RECEIVER_QUALIFIER />
<SYNTAX_IDENTIFIER />
<SYNTAX_VERSION />
<BGM>227</BGM>
<GRP>
<IDENTIFIER_BY />
<IDENTIFIER_SU />
<DATE_4 />
<REF_ON />
</GRP>
</CNT>
</SEEDELFOR>
An the solution would be:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="CNT">
<xsl:copy>
<xsl:apply-templates select="*[local-name()!='BGM']" />
</xsl:copy>
</xsl:template>
<xsl:template match="GRP">
<xsl:element name="GRP">
<xsl:apply-templates />
<xsl:copy-of select="../BGM" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
http://xsltransform.net/eieE3Q5
<!-- remove BGM at CNT-->
<xsl:template match="BGM"/>
<!--copy the data from ADD/CONTACT with Qualifier EM to GRP, so it can be used in the mapping to set EMAIL from Customer-->
<xsl:template match="GRP">
<xsl:copy>
<xsl:for-each select ="./ADD/CONTACT">
<xsl:if test="./QUALIFIER='EM'">
<CONTACT_EMAIL>
<xsl:value-of select="NUMBER"/>
</CONTACT_EMAIL>
</xsl:if>
<xsl:if test="./QUALIFIER='TE'">
<CONTACT_TEL>
<xsl:value-of select="NUMBER"/>
</CONTACT_TEL>
</xsl:if>
<xsl:if test="./QUALIFIER='FX'">
<CONTACT_FAX>
<xsl:value-of select="NUMBER"/>
</CONTACT_FAX>
</xsl:if>
</xsl:for-each>
<!--copy BGM from CNT to GRP -->
<xsl:copy-of select="../BGM" />
<!--copy all other nodes-->
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>

xsl 1.0 muenchian sum to sum quantity field per compound key

For a SAP PO xsl 1.0 mapping I need to map an 'exotic' file coming from our warehouse where I need to group/sum per order (RECH) a QTY field on a combination of a line identifier (MASTER_PO_LINE_NO) and an Itemnumber (SKU). Each line (RECL) is in a header (RECH).
INPUT:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
<ns0:Message1>
<MARCXML>
<RCIC>
<RECH>
<SALESID>24000</SALESID>
<RECL>
<LINE_NO>1</LINE_NO>
<QTY_EXPE>1592</QTY_EXPE>
<SKU>11207-210</SKU>
<MASTER_PO_LINE_NO>10</MASTER_PO_LINE_NO>
</RECL>
<RECL>
<LINE_NO>2</LINE_NO>
<QTY_EXPE>1000</QTY_EXPE>
<SKU>11207-210</SKU>
<MASTER_PO_LINE_NO>10</MASTER_PO_LINE_NO>
</RECL>
<RECL>
<LINE_NO>3</LINE_NO>
<QTY_EXPE>175</QTY_EXPE>
<SKU>11207-210</SKU>
<MASTER_PO_LINE_NO>20</MASTER_PO_LINE_NO>
</RECL>
</RECH>
<RECH>
<SALESID>25001</SALESID>
<RECL>
<LINE_NO>1</LINE_NO>
<QTY_EXPE>440</QTY_EXPE>
<SKU>20000-210</SKU>
<MASTER_PO_LINE_NO>10</MASTER_PO_LINE_NO>
</RECL>
</RECH>
</RCIC>
</MARCXML>
</ns0:Message1>
</ns0:Messages>
Required OUTPUT (Qty for 11207-210 = 1592 + 1000):
<?xml version="1.0" encoding="UTF-8"?>
<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
<ns0:Message1>
<MARCXML>
<RCIC>
<RECH>
<SALESID>24000</SALESID>
<RECL>
<LINE_NO>1</LINE_NO>
<QTY_EXPE>2592</QTY_EXPE>
<SKU>11207-210</SKU>
<MASTER_PO_LINE_NO>10</MASTER_PO_LINE_NO>
</RECL>
<RECL>
<LINE_NO>3</LINE_NO>
<QTY_EXPE>175</QTY_EXPE>
<SKU>11207-210</SKU>
<MASTER_PO_LINE_NO>20</MASTER_PO_LINE_NO>
</RECL>
</RECH>
<RECH>
<SALESID>25001</SALESID>
<RECL>
<LINE_NO>1</LINE_NO>
<QTY_EXPE>440</QTY_EXPE>
<SKU>20000-210</SKU>
<MASTER_PO_LINE_NO>10</MASTER_PO_LINE_NO>
</RECL>
</RECH>
</RCIC>
</MARCXML>
</ns0:Message1>
</ns0:Messages>
There are plenty of examples about muenchian grouping but I didn't manage to solve my requirement yet. To be honest I got as far as:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
<ns0:Message1>
<MARCXML>
<RCIC>
<RECH>5284</RECH>
<RECH>5284</RECH>
<RECH>5284</RECH>
</RCIC>
</MARCXML>
</ns0:Message1>
</ns0:Messages>
With the following xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="kMSTR_PO_LN_SKU" match="RECL"
use="concat(MASTER_PO_LINE_NO, '#', SKU)"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="RECH">
<xsl:copy>
<xsl:value-of select="sum(//MARCXML/RCIC/RECH/RECL/QTY_CHECKED_IN)" />
<xsl:for-each select="/RECL[generate-id()=generate-id(key('kMSTR_PO_LN_SKU',concat(MASTER_PO_LINE_NO,'-',SKU))[1])]">
<xsl:copy>
<SKU>
<xsl:value-of select="SKU"/>
</SKU>
<Quantity>
<xsl:value-of select="sum(key('kMSTR_PO_LN_SKU',concat(MASTER_PO_LINE_NO,'-',RECL))/QTY_EXPE)"/>
</Quantity>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Hope someone can help me on my way here
AFAICT, this produces the required output - but having only a single example with somewhat ambiguous rules it could be a coincidence. In any case, it should provide you with a starting point.
XSLT 1.0
<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"/>
<xsl:strip-space elements="*"/>
<xsl:key name="k1" match="RECL" use="concat(MASTER_PO_LINE_NO, '|', SKU)"/>
<!-- identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="RECH">
<xsl:copy>
<xsl:copy-of select="SALESID"/>
<xsl:for-each select="RECL[generate-id()=generate-id(key('k1', concat(MASTER_PO_LINE_NO,'|',SKU))[1])]">
<xsl:copy>
<xsl:copy-of select="LINE_NO"/>
<QTY_EXPE>
<xsl:value-of select="sum(key('k1', concat(MASTER_PO_LINE_NO,'|',SKU))/QTY_EXPE)" />
</QTY_EXPE>
<xsl:copy-of select="SKU | MASTER_PO_LINE_NO"/>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Added:
In order to summarize every order (RECH) separately, you must add an identifier of the order to the key:
XSLT 1.0
<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"/>
<xsl:strip-space elements="*"/>
<xsl:key name="k1" match="RECL" use="concat(MASTER_PO_LINE_NO, '|', SKU, '|', generate-id(..))"/>
<!-- identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="RECH">
<xsl:copy>
<xsl:copy-of select="SALESID"/>
<xsl:for-each select="RECL[generate-id()=generate-id(key('k1', concat(MASTER_PO_LINE_NO,'|',SKU, '|', generate-id(..)))[1])]">
<xsl:copy>
<xsl:copy-of select="LINE_NO"/>
<QTY_EXPE>
<xsl:value-of select="sum(key('k1', concat(MASTER_PO_LINE_NO,'|',SKU, '|', generate-id(..)))/QTY_EXPE)" />
</QTY_EXPE>
<xsl:copy-of select="SKU | MASTER_PO_LINE_NO"/>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

Modifying the XML element value upon condiion by XSLT

I have xml
<PhoneNumberDetails>
<PhoneNumber>
<Number>4162880001</Number>
<TimeStamp>2016-08-16T07:07:44-04:00</TimeStamp>
</PhoneNumber>
<PhoneNumber>
<Number>4162880002</Number>
<TimeStamp>2016-08-16T07:07:44-04:00</TimeStamp>
</PhoneNumber>
</PhoneNumberDetails>
This is input to a XSL. In this XSL i retrieve a phone number from context variable stored in one of the previous XSLT and if it matches to any phone number in above xml, I need to update the TimeStamp to new current Timestamp. I need help in this part.
The XSLT Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="dp date" exclude-result-prefixes="dp">
<xsl:variable name="currentTimeStamp" select="date:date-time()"/>
<xsl:output method="xml"/>
<xsl:template match="PhoneNumberDetails">
<xsl:variable name="savedPhoneNum" select="dp:variable('var://context/name/phonenum')"/>
<xsl:choose>
<xsl:when test="/*[local-name()='PhoneNumberDetails']/*[local-name()='PhoneNumber']/*[local-name()='Number']=$savedPhoneNum">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="phonenumber"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="phonenumber" match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="PhoneNumberDetails">
<PhoneNumberDetails>
<xsl:apply-templates select="#* | *"/>
<PhoneNumber>
<Number>
<xsl:value-of select="dp:variable('var://context/name/phonenum')"/>
</Number>
<TimeStamp>
<xsl:value-of select="$currentTimeStamp"/>
</TimeStamp>
</PhoneNumber>
</PhoneNumberDetails>
</xsl:template>
</xsl:stylesheet>
If the phone number does not matches any number in XML i need to add a new element to the above xml and this part works. For e.g.
<PhoneNumber>
<Number>New number</Number>
<TimeStamp>Current TimeStamp</TimeStamp>
</PhoneNumber>
Why can't you do simply:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions"
xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="dp date">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="savedPhoneNum" select="dp:variable('var://context/name/phonenum')"/>
<!-- identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="TimeStamp[../Number=$savedPhoneNum]">
<xsl:copy>
<xsl:value-of select="date:date-time()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="PhoneNumberDetails[not(PhoneNumber/Number=$savedPhoneNum)]">
<xsl:copy>
<xsl:apply-templates/>
<PhoneNumber>
<Number>New number</Number>
<TimeStamp>Current TimeStamp</TimeStamp>
</PhoneNumber>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I suggest you start with something like this. Don't use an absolute path to select the phone number, use it from that context node where the template matches.
<xsl:template match="PhoneNumber">
<xsl:copy>
<xsl:copy-of select="Number"/>
<xsl:variable name="savedPhoneNum" select="dp:variable('var://context/name/phonenum')"/>
<TimeStamp>
<xsl:choose>
<xsl:when test="Number=$savedPhoneNum">
<xsl:value-of select="$currentTimeStamp"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="TimeStamp"/>
</xsl:otherwise>
</xsl:choose>
</TimeStamp>
</xsl:copy>
</xsl:template>
Note that I assume that you don't have a (non-shown) namespace on the elements of your input xml. If yes, keep your *[local-name()=""] construct, but then the namespace would have to be added to the match="PhoneNumber" and to the TimeStamp output as well.

XSLT1.0 Remove repeat nodes

I am trying to apply Muenchian grouping to eliminate duplicate nodes, but I seem not to be able to make it work.
Input:
<GetUsersByRoleRspMsg>
<UserList>
<User>
<UserId>PPAUSER1</UserId>
<Email>xyz#gmail.com</Email>
</User>
<User>
<UserId>PPAUSER1</UserId>
<Email>xyz#gmail.com</Email>
</User>
</UserList>
</GetUsersByRoleRspMsg>
Required:
<GetUsersByRoleRspMsg>
<UserList>
<User>
<UserId>PPAUSER1</UserId>
<Email>xyz#gmail.com</Email>
</User>
</UserList>
</GetUsersByRoleRspMsg>
The critical part of my code is
<xsl:key name="userIdEmailPair"
match="User"
use="concat(UserId,' ',Email)"/>
<xsl:copy>
<xsl:for-each select="User[
count(. | key('userIdEmailPair',
concat(UserId,' ',Email))[1])
= 1]">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:copy>
I don't see any problem with your grouping code. If you try:
<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"/>
<xsl:strip-space elements="*"/>
<xsl:key name="userIdEmailPair" match="User" use="concat(UserId,' ',Email)"/>
<!-- identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="UserList">
<xsl:copy>
<xsl:for-each select="User[count(. | key('userIdEmailPair',concat(UserId,' ',Email))[1]) = 1]">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
you will get the result you're looking for.
Of course, you could shorten the last template to:
<xsl:template match="UserList">
<xsl:copy>
<xsl:copy-of select="User[count(. | key('userIdEmailPair',concat(UserId,' ',Email))[1]) = 1]"/>
</xsl:copy>
</xsl:template>

Remove Duplicates from a list XSLT 1.0 based on element value

I need help with writing a function in xslt 1.0 that I can pass a list and it'll return the list with duplicates removed. It needs to be a template that I can easily clone or modify for other lists since there are several lists that I want to be able to run this.
Here is one example:
Input list:
<Diagnoses>
<Code>444.4</Code>
<Code>959.99</Code>
<Code>524</Code>
<Code>444.4</Code>
</Diagnoses>
Desired Output, after the duplicate code value 444.4 is removed:
<Diagnoses>
<Code>444.4</Code>
<Code>959.99</Code>
<Code>524</Code>
</Diagnoses>
Here is what I have so far, but it doesn't seem to be working:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:math="http://exslt.org/math"
xmlns:exsl="http://exslt.org/common"
xmlns:data="http://example.com/data" version="1.0"
extension-element-prefixes="math exsl"
exclude-result-prefixes="math exsl data">
<xsl:output omit-xml-declaration="yes" />
<xsl:variable name="DiagnosesList" select="Diagnoses"/>
<Diagnoses>
<xsl:call-template name="DedupeLists">
<xsl:with-param name="Input" select = "exsl:node-set($DiagnosesList)" />
</xsl:call-template>
</Diagnoses>
<xsl:template name="DedupeLists">
<xsl:param name = "Input" />
<xsl:for-each select="$Input/*">
<xsl:if test="Code[not(preceding::Code)]">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
#lingamurthy,
Just
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Code[. = preceding-sibling::Code]"/>
</xsl:stylesheet>
This is one way:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Code[not(. = preceding-sibling::Code)]">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Code"/>
</xsl:stylesheet>