0
不重複我有一個包含表單的一些節點傳入的XML文檔:整合數據和XSLT
<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
和不同還能避免重複。
我沒有可用的'xsl:for-each-group',所以我我會試試這個。 – FrustratedWithFormsDesigner 2012-08-13 15:42:49