我需要改變這個輸入XML:XSLT1轉型
<Log1>
<Connection User="Peter" Host="Computer01" Port="22"/>
<Connection User="Peter" Host="Computer02" Port="22"/>
<Connection User="Peter" Host="Computer02" Port="80"/>
<Connection User="David" Host="Computer01" Port="8080"/>
<Connection User="David" Host="Computer01" Port="8080"/>
<Connection User="David" Host="Computer01" Port="8080"/>
<Connection User="David" Host="Computer03" Port="22"/>
<Connection User="David" Host="Computer04" Port="21"/>
</Log1>
成輸出XML:
<Log2>
<Event Name="David" Target="Computer01|Computer03|Computer04"/>
<Event Name="Peter" Target="Computer01|Computer02"/>
</Log2>
到目前爲止,我用Muenchian分組的和得到的東西,如:
<Log2>
<Event Name="David" Target="Computer01|Computer01|Computer01|Computer03|Computer04"/>
<Event Name="Peter" Target="Computer01|Computer02|computer02"/>
</Log2>
問題是我無法擺脫我的輸出中的重複機器。
這裏是我的XSLT:
<xsl:key name="myKey" match="Connection" use="@User"/>
<xsl:variable name="separator" select="'|'"/>
<xsl:template match="Log1">
<xsl:element name="Log2">
<xsl:for-each select="Connection[count(. | key('myKey', @User)[1]) = 1]">
<xsl:sort select="@User" />
<xsl:element name="Event">
<xsl:attribute name="Name">
<xsl:value-of select="@User" />
</xsl:attribute>
<xsl:attribute name="Target">
<xsl:for-each select="key('myKey', @User)">
<xsl:sort select="@Host" />
<xsl:value-of select="@Host" />
<xsl:if test="position() != last()">
<xsl:value-of select="$separator" />
</xsl:if>
</xsl:for-each>
</xsl:attribute>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
難道你們幫我使用XSLT 1.0處理器?
請顯示您當前的XSLT樣式表。 –
添加了當前的XSLT,非常感謝! – nereide