次の形式のノードを含む着信 XML ドキュメントがあります。
<userOptions>
<userOption>
<type>A</type>
<plan>
<frequency>MONTHLY</frequency>
</plan>
<method>
<methodType>X1</methodType>
</method>
</userOption>
<userOption>
<type>B</type>
<plan>
<frequency>QUARTERLY</frequency>
</plan>
<method>
<methodType>X2</methodType>
</method>
</userOption>
<userOption>
<type>A</type>
<plan>
<frequency>3MONTH</frequency>
</plan>
<method>
<methodType>X1-B</methodType>
</method>
</userOption>
</userOptions>
これを統合して、次のようなものに変換する必要があります。
<userOptions>
<userOption>
<type>A</type>
<plan>
<frequency>3MONTH</frequency>
<methodType>X1-B</methodType>
</plan>
<plan>
<frequency>MONTHLY</frequency>
<methodType>X1</methodType>
</plan>
<userOption>
<userOption>
<type>B</type>
<plan>
<frequency>QUARTERLY</frequency>
<methodType>X2</methodType>
</plan>
<userOption>
</userOptions>
私の現在の変換は次のようになります。
<userOptions>
<xsl:for-each select="//userOptions">
<userOption>
<type>
<xsl:value-of select="type" />
</type>
<xsl:variable name="currentType" select="type"/>
<xsl:message><xsl:value-of select="$currentType"/></xsl:message>
<xsl:variable name="currentMethod" select="method/methodType"/>
<xsl:message><xsl:value-of select="$currentMethod/></xsl:message>
<plan>
<frequency>
<xsl:value-of select="plan/frequency" />
</frequency>
<method>
<xsl:value-of select="method/methodType" />
</method>
</plan>
<xsl:for-each select="../userOptions[type=$currentType and method/methodType!=$currentMethod]">
<plan>
<frequency>
<xsl:value-of select="plan/frequency" />
</frequency>
<method>
<xsl:value-of select="method/methodType" />
</method>
</plan>
</xsl:for-each>
</userOption>
</xsl:for-each>
</userOptions>
問題は、次のような重複が発生することです。
<userOption>
<type>A</type>
<plan>
<frequency>3MONTH</frequency>
<methodType>X1-B</methodType>
</plan>
<plan>
<frequency>MONTHLY</frequency>
<methodType>X1</methodType>
</plan>
<userOption>
<userOption>
<type>A</type>
<plan>
<frequency>MONTHLY</frequency>
<methodType>X1</methodType>
</plan>
<plan>
<frequency>3MONTH</frequency>
<methodType>X1-B</methodType>
</plan>
<userOption>
type
一致するレコードと異なるレコードを統合する方法がわかりませんmethodType
が、重複を回避する方法もわかりません。