Learning XSL, relegated at this time to XSL 1.0, trying to produce a distinct set as well perform subsequent pass using match modes constructs.
If the modes are not introduced all is well.
As soon as modes are introduced the translation fails.
Any help would be appreciated.
Exempliary xml:
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<node>
<category comat="0" catat="AC1" catatt="AD1">C1</category>
<desc>D1</desc>
</node>
<node>
<category comat="0" catat="AC2" catatt="AD2">C2</category>
<desc>D2</desc>
</node>
<node>
<category comat="0" catat="AC1" catatt="AD1">C1</category>
<desc>D1</desc>
</node>
<node>
<category comat="0" catat="AC3" catatt="AD3">C3</category>
<desc>D3</desc>
</node>
</dataset>
Sample Munchian producing distinct records.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/><!-- New document created with EditiX at Thu Aug 05 16:51:01 PDT 2010 -->
<xsl:key name="nodekey" match="node/category" use="concat(@catat,'_',@catatt)"/>
<xsl:template match="dataset">
<CAT>
<xsl:apply-templates />
</CAT>
</xsl:template>
<xsl:template match="dataset" >
<CATD>
<xsl:for-each select="node/category[generate-id()= generate-id(key('nodekey',concat(@catat,'_',@catatt))[1])]">
<CAT_D>
<xsl:value-of select="concat(@catat,'_',@catatt)"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="."/>
</CAT_D>
</xsl:for-each>
</CATD>
</xsl:template>
</xsl:stylesheet>
Sample Output:
<?xml version="1.0" encoding="UTF-8"?>
<CATD xmlns:exslt="http://exslt.org/common">
<CAT_D>AC1_AD1_C1</CAT_D>
<CAT_D>AC2_AD2_C2</CAT_D>
<CAT_D>AC3_AD3_C3</CAT_D>
</CATD>
However, when modes are added the same translations fail?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/><!-- New document created with EditiX at Thu Aug 05 16:51:01 PDT 2010 -->
<xsl:key name="nodekey" match="node/category" use="concat(@catat,'_',@catatt)"/>
<xsl:template match="dataset">
<UCAT>
<xsl:apply-templates mode="ucatmode"/>
</UCAT>
<DCAT>
<xsl:apply-templates mode="catmode"/>
</DCAT>
</xsl:template>
<xsl:template match="dataset" mode="ucatmode">
<DESC>
<xsl:for-each select="node/category[generate-id()= generate-id(key('nodekey',concat(@catat,'_',@catatt))[1])]">
<CAT_D>
<xsl:value-of select="concat(@catat,'_',@catatt)"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="."/>
</CAT_D>
</xsl:for-each>
</DESC>
</xsl:template>
<xsl:template match="dataset/node/desc" mode="catmode">
<CATQ>
<xsl:value-of select="."/>
</CATQ>
</xsl:template>
</xsl:stylesheet>