これは、xml のスニペットです。
<sample>
        <test>
            <Cell1>John</Cell1>
            <Cell2>A</Cell2>
            <Cell4>xy</Cell4>
        </test>
        <test>
            <Cell1>Jack</Cell1>
            <Cell2>B</Cell2>
            <Cell3>Red</Cell3>
            <Cell6>10</Cell6>
        </test>
        <test>
            <Cell1>John,Jade</Cell1>
            <Cell2>A,Y</Cell2>
            <Cell4>1</Cell4>
        </test>
        <test>
            <Cell1>John,Jade</Cell1>
            <Cell2>A B,X</Cell2>
            <Cell3>Blue</Cell3>
        </test>
    </sample>
条件:
Cell2コンマが含まれている場合は値を分割し、前Cell2に同じ値が含まれているかどうかを確認し、同様Cell2にスペースが含まれている場合は値を分割し、前Cell2に同じ値が含まれているかどうかを確認します->そうであれば無視します。
これは私が出力を望む方法です:
<Cell2>A</Cell2>
<Cell2>B</Cell2>
<Cell2>Y</Cell2>
<Cell2>X</Cell2>
これは私が書いた xslt です: (コメントを見てください)
<xsl:template match="sample">
        <xsl:for-each select="test">
                <xsl:choose>
                    <xsl:when test="contains(Cell2,',')">
                        <xsl:variable name="token1Cell2" select="tokenize(Cell2,',')"/>
                        <xsl:for-each select="$token1Cell2">
                            <xsl:choose>
                                <xsl:when test="contains(.,' ')">
                                    <xsl:variable name="token2Cell2" select="tokenize(.,' ')"/>
                                    <xsl:for-each select="$token2Cell2">
              <!-- I tried to check if the preceding sibling element test/Cell2 contains the text that is not equal to the current text. But I know what I am doing is wrong as I am inside for-each tokenize. How to get the preceding-sibling? -->
                                      <xsl:if test="preceding-sibling::test/
Cell2/text() != '.'">
                                        <Cell2>
                                            <xsl:value-of select="."/>
                                        </Cell2>
                                        </xsl:if>
                                    </xsl:for-each>
                                </xsl:when>
                                <xsl:otherwise>
                                <xsl:if test="preceding-sibling::test/Cell2/text() != '.'">
                                    <Cell2>
                                        <xsl:value-of select="."/>
                                    </Cell2>
                                </xsl:if>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:for-each>
                    </xsl:when>
                    <xsl:otherwise>
                        <Cell2>
                            <xsl:value-of select="Cell2"/>
                        </Cell2>
                    </xsl:otherwise>
                </xsl:choose>
        </xsl:for-each>
    </xsl:template>
どうすれば出力を達成できますか? 何か案は??