Advertisement
desdemona

xslt map

Dec 2nd, 2012
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 3.04 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.                xmlns:derp1="derp1.amber"
  4.                xmlns:derp2="derp2.amber">
  5.   <xsl:output method="html"/>
  6.  
  7.   <xsl:template name="map">
  8.     <xsl:param name="funkcja"/>
  9.     <xsl:param name="lista"/>
  10.     <xsl:for-each select="$lista/uczestnik">
  11.       <xsl:copy>
  12.         <xsl:apply-templates select="$funkcja">
  13.           <xsl:with-param name="arg" select="."/>
  14.         </xsl:apply-templates>
  15.       </xsl:copy>
  16.     </xsl:for-each>
  17.   </xsl:template>
  18.  
  19.   <xsl:template name ="filter">
  20.     <xsl:param name="funkcja"/>
  21.     <xsl:param name="lista"/>
  22.     <xsl:for-each select="$lista">
  23.       <xsl:variable name="fTest">
  24.         <xsl:apply-templates select="$funkcja">
  25.           <xsl:with-param name="arg" select="."/>
  26.         </xsl:apply-templates>
  27.       </xsl:variable>
  28.       <xsl:if test="string($fTest)='true'">
  29.         <xsl:copy-of select="."/>
  30.       </xsl:if>
  31.     </xsl:for-each>
  32.   </xsl:template>
  33.  
  34.   <xsl:template name="reduce">
  35.     <xsl:param name="funkcja"/>
  36.     <xsl:param name="wPocz"/>
  37.     <xsl:param name="lista"/>
  38.     <xsl:choose>
  39.       <xsl:when test="not($lista)">
  40.         <xsl:copy-of select="$wPocz"/>
  41.       </xsl:when>
  42.       <xsl:otherwise>
  43.         <xsl:variable name="fWynik">
  44.           <xsl:apply-templates select="$funkcja">
  45.             <xsl:with-param name="arg1" select="$wPocz"/>
  46.             <xsl:with-param name="arg2" select="$lista[1]"/>
  47.           </xsl:apply-templates>
  48.         </xsl:variable>
  49.         <xsl:call-template name="reduce">
  50.           <xsl:with-param name="funkcja" select="$funkcja"/>
  51.           <xsl:with-param name="wPocz" select="$fWynik"/>
  52.           <xsl:with-param name="lista" select="$lista[position()>1]"/>
  53.         </xsl:call-template>
  54.       </xsl:otherwise>
  55.     </xsl:choose>
  56.   </xsl:template>
  57.  
  58.   <xsl:template match="*[namespace-uri()='derp1.amber']">
  59.     <xsl:param name="arg"/>
  60.     <tr>
  61.       <td>
  62.         <xsl:value-of select="$arg/nazwa"/>
  63.       </td>
  64.       <td>
  65.         <xsl:value-of select="$arg/zdolnosc"/>
  66.       </td>
  67.       <td>
  68.         <xsl:value-of select="$arg/sms"/>
  69.       </td>
  70.       <td>
  71.         <xsl:value-of select="$arg/ocena"/>
  72.       </td>
  73.       <td>
  74.         <xsl:value-of select="$arg/medialny"/>
  75.       </td>
  76.     </tr>
  77.   </xsl:template>
  78.   <xsl:variable name="funkcjadomap" select="document('')/*/derp1:*[1]" />
  79.   <derp1:derp1/>
  80.  
  81.  
  82.  
  83.  
  84.  
  85.   <xsl:template match="/">
  86.     <html>
  87.       <body>      
  88.         <h2>Uczestnicy Show</h2>
  89.         <table border="1">
  90.           <tr bgcolor="#9acd32">
  91.             <th>Nazwa</th>
  92.             <th>Zdolność</th>
  93.             <th>Sms</th>
  94.             <th>Ocena</th>
  95.             <th>Medialny</th>
  96.           </tr>
  97.           <xsl:call-template name="map">
  98.             <xsl:with-param name="funkcja" select="$funkcjadomap"/>
  99.             <xsl:with-param name="lista" select="show"/>
  100.           </xsl:call-template>
  101.         </table>
  102.       </body>
  103.     </html>
  104.   </xsl:template>
  105.  
  106. </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement