home *** CD-ROM | disk | FTP | other *** search
- <xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:msxsl="urn:schemas-microsoft-com:xslt"
- >
-
- <xsl:output method="text"/>
-
- <xsl:variable name="Root" select="/"/>
-
- <!-- Obtain all different "name"s -->
- <xsl:variable name="sortedNames">
- <xsl:for-each select="/root/data/item">
- <xsl:sort select="@name"/>
- <xsl:element name="name">
- <xsl:value-of select="@name"/>
- </xsl:element>
- </xsl:for-each>
- </xsl:variable>
-
- <xsl:variable name="uniqueNames">
- <xsl:for-each select="msxsl:node-set($sortedNames)/name[position()=1 or . != preceding-sibling::name[1]]">
- <xsl:element name="name">
- <xsl:value-of select="."/>
- </xsl:element>
- </xsl:for-each>
- </xsl:variable>
-
- <!-- Obtain all different "id"s -->
- <xsl:variable name="sortedIds">
- <xsl:for-each select="/root/data/item">
- <xsl:sort select="@id"/>
- <xsl:element name="id">
- <xsl:value-of select="@id"/>
- </xsl:element>
- </xsl:for-each>
- </xsl:variable>
-
- <xsl:variable name="uniqueIds">
- <xsl:for-each select="msxsl:node-set($sortedIds)/id[position()=1 or . != preceding-sibling::id[1]]">
- <xsl:element name="id">
- <xsl:value-of select="."/>
- </xsl:element>
- </xsl:for-each>
- </xsl:variable>
-
-
-
-
- <xsl:template match="/">
- <!-- Output the "title" line -->
- <xsl:text>id,</xsl:text>
- <xsl:for-each select="msxsl:node-set($uniqueNames)/*">
- <xsl:value-of select="."/>
- <xsl:if test="position() != last()">
- <xsl:text>,</xsl:text>
- </xsl:if>
- </xsl:for-each>
-
- <!-- Output every "data" line -->
- <xsl:for-each select="msxsl:node-set($uniqueIds)/id">
- <xsl:variable name="thisId" select="."/>
-
- <!-- Output "NL" + "id" -->
- <xsl:text>
</xsl:text>
- <xsl:value-of select="."/>
- <xsl:text>,</xsl:text>
-
- <!-- Output the corresponding "value" for every "id" -->
- <xsl:for-each select="msxsl:node-set($uniqueNames)/name">
- <xsl:variable name="thisName" select="."/>
- <xsl:value-of select="$Root/root/data/item[@id=$thisId][@name=$thisName][1]/@value"/>
- <xsl:if test="position() != last()">
- <xsl:text>,</xsl:text>
- </xsl:if>
- </xsl:for-each>
- </xsl:for-each>
-
-
- </xsl:template>
-
- </xsl:stylesheet>
-