desdemona

kupa. xslt

Dec 2nd, 2012
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.06 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.                 xmlns:derp3="derp3.amber">
  6.   <xsl:output method="html"/>
  7.  
  8.   <xsl:template name="map">
  9.     <xsl:param name="funkcja"/>
  10.     <xsl:param name="lista"/>
  11.     <xsl:for-each select="$lista/uczestnik">
  12.       <xsl:copy>
  13.         <xsl:apply-templates select="$funkcja">
  14.           <xsl:with-param name="arg" select="."/>
  15.         </xsl:apply-templates>
  16.       </xsl:copy>
  17.     </xsl:for-each>
  18.   </xsl:template>
  19.  
  20.  
  21.   <xsl:template name ="filter">
  22.     <xsl:param name="funkcja"/>
  23.     <xsl:param name="lista"/>
  24.     <xsl:for-each select="$lista/uczestnik">
  25.       <xsl:variable name="fTest">
  26.         <xsl:apply-templates select="$funkcja">
  27.           <xsl:with-param name="arg" select="."/>
  28.         </xsl:apply-templates>
  29.       </xsl:variable>
  30.       <xsl:if test="string($fTest)='true'">
  31.         <xsl:copy-of select="."/>
  32.       </xsl:if>
  33.     </xsl:for-each>
  34.   </xsl:template>
  35.  
  36.   <xsl:template name="reduce">
  37.     <xsl:param name="funkcja"/>
  38.     <xsl:param name="wPocz"/>
  39.     <xsl:param name="lista"/>
  40.     <xsl:choose>
  41.       <xsl:when test="not($lista)">
  42.         <xsl:copy-of select="$wPocz"/>
  43.       </xsl:when>
  44.       <xsl:otherwise>
  45.         <xsl:variable name="fWynik">
  46.           <xsl:apply-templates select="$funkcja">
  47.             <xsl:with-param name="arg1" select="$wPocz"/>
  48.             <xsl:with-param name="arg2" select="$lista[1]"/>
  49.           </xsl:apply-templates>
  50.         </xsl:variable>
  51.         <xsl:call-template name="reduce">
  52.           <xsl:with-param name="funkcja" select="$funkcja"/>
  53.           <xsl:with-param name="wPocz" select="$fWynik"/>
  54.           <xsl:with-param name="lista" select="$lista[position()>1]"/>
  55.         </xsl:call-template>
  56.       </xsl:otherwise>
  57.     </xsl:choose>
  58.   </xsl:template>
  59.  
  60.   <xsl:template match="*[namespace-uri()='derp1.amber']">
  61.     <xsl:param name="arg"/>
  62.     <tr>
  63.       <td>
  64.         <xsl:value-of select="$arg/nazwa"/>
  65.       </td>
  66.       <td>
  67.         <xsl:value-of select="$arg/zdolnosc"/>
  68.       </td>
  69.       <td>
  70.         <xsl:value-of select="$arg/sms"/>
  71.       </td>
  72.       <td>
  73.         <xsl:value-of select="$arg/ocena"/>
  74.       </td>
  75.       <td>
  76.         <xsl:value-of select="$arg/medialny"/>
  77.       </td>
  78.     </tr>
  79.   </xsl:template>
  80.   <xsl:variable name="funkcjadomap" select="document('')/*/derp1:*[1]" />
  81.   <derp1:derp1/>
  82.  
  83.  
  84.   <xsl:template match="*[namespace-uri()='derp2.amber']">
  85.     <xsl:param name="arg"/>
  86.     <xsl:choose>
  87.       <xsl:when test="$arg/medialny = 't'">
  88.         <xsl:value-of select="'true'"/>
  89.       </xsl:when>
  90.       <xsl:otherwise>
  91.         <xsl:value-of select="'false'"/>
  92.       </xsl:otherwise>
  93.     </xsl:choose>
  94.     <xsl:value-of select="$arg/nazwa"/>
  95.   </xsl:template>
  96.   <xsl:variable name="funfilter" select="document('')/*/derp2:*[1]" />
  97.   <derp2:derp2/>
  98.  
  99.   <xsl:template match="/">
  100.     <html>
  101.       <body>      
  102.         <h2>Uczestnicy Show</h2>
  103.         <table border="1">
  104.           <tr bgcolor="#9acd32">
  105.             <th>Nazwa</th>
  106.             <th>Zdolność</th>
  107.             <th>Sms</th>
  108.             <th>Ocena</th>
  109.             <th>Medialny</th>
  110.           </tr>
  111.           <xsl:call-template name="map">
  112.             <xsl:with-param name="funkcja" select="$funkcjadomap"/>
  113.             <xsl:with-param name="lista" select="show"/>
  114.           </xsl:call-template>
  115.         </table>
  116.         <br/>
  117.         <br/>
  118.        
  119.         <h2>Medialni uczestnicy show</h2>
  120.         <table border="1">
  121.           <tr bgcolor="#9acd32">
  122.             <th>Nazwa</th>
  123.             <th>Zdolność</th>
  124.             <th>Sms</th>
  125.             <th>Ocena</th>
  126.             <th>Medialny</th>
  127.           </tr>
  128.           <xsl:call-template name="filter">
  129.             <xsl:with-param name="funkcja" select="$funfilter"/>
  130.             <xsl:with-param name="lista" select="show"/>
  131.           </xsl:call-template>
  132.         </table>
  133.       </body>
  134.     </html>
  135.   </xsl:template>
  136.  
  137. </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment