home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F46756_xsPivot.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-07-22  |  2.2 KB  |  82 lines

  1. <xsl:stylesheet version="1.0"
  2.                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.                 xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
  4. >
  5.  
  6.     <xsl:output method="text"/>
  7.  
  8.     <xsl:variable name="Root" select="/"/> 
  9.     
  10.     <!-- Obtain all different "name"s -->
  11.     <xsl:variable name="sortedNames">
  12.         <xsl:for-each select="/root/data/item">
  13.             <xsl:sort select="@name"/>
  14.                 <xsl:element name="name">
  15.                     <xsl:value-of select="@name"/>
  16.                 </xsl:element>
  17.         </xsl:for-each>
  18.     </xsl:variable>
  19.     
  20.     <xsl:variable name="uniqueNames">
  21.         <xsl:for-each select="msxsl:node-set($sortedNames)/name[position()=1 or . != preceding-sibling::name[1]]">
  22.             <xsl:element name="name">
  23.                 <xsl:value-of select="."/>
  24.             </xsl:element>
  25.         </xsl:for-each>
  26.     </xsl:variable>
  27.     
  28.     <!-- Obtain all different "id"s -->
  29.     <xsl:variable name="sortedIds">
  30.         <xsl:for-each select="/root/data/item">
  31.             <xsl:sort select="@id"/>
  32.                 <xsl:element name="id">
  33.                     <xsl:value-of select="@id"/>
  34.                 </xsl:element>
  35.         </xsl:for-each>
  36.     </xsl:variable>
  37.     
  38.     <xsl:variable name="uniqueIds">
  39.         <xsl:for-each select="msxsl:node-set($sortedIds)/id[position()=1 or . != preceding-sibling::id[1]]">
  40.             <xsl:element name="id">
  41.                 <xsl:value-of select="."/>
  42.             </xsl:element>
  43.         </xsl:for-each>
  44.     </xsl:variable>
  45.     
  46.     
  47.  
  48.  
  49. <xsl:template match="/">
  50.     <!-- Output the "title" line -->
  51.     <xsl:text>id,</xsl:text>
  52.     <xsl:for-each select="msxsl:node-set($uniqueNames)/*">
  53.         <xsl:value-of select="."/>
  54.         <xsl:if test="position() != last()">
  55.             <xsl:text>,</xsl:text>
  56.         </xsl:if>
  57.     </xsl:for-each>
  58.     
  59.     <!-- Output every "data" line -->
  60.     <xsl:for-each select="msxsl:node-set($uniqueIds)/id">
  61.         <xsl:variable name="thisId" select="."/>
  62.         
  63.         <!-- Output "NL" + "id" -->
  64.         <xsl:text> </xsl:text>
  65.         <xsl:value-of select="."/>
  66.         <xsl:text>,</xsl:text>
  67.         
  68.         <!-- Output the corresponding "value" for every "id" -->
  69.         <xsl:for-each select="msxsl:node-set($uniqueNames)/name">
  70.             <xsl:variable name="thisName" select="."/>
  71.             <xsl:value-of select="$Root/root/data/item[@id=$thisId][@name=$thisName][1]/@value"/>
  72.             <xsl:if test="position() != last()">
  73.                 <xsl:text>,</xsl:text>
  74.             </xsl:if>
  75.         </xsl:for-each>
  76.     </xsl:for-each>
  77.     
  78.     
  79. </xsl:template>
  80.  
  81. </xsl:stylesheet>
  82.