matrix.xsl 3.6 KB
Newer Older
1 2 3 4 5 6
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  <xsl:output method="text"/>

  <xsl:param name="fragments"
7 8
             select="document('../relaxng/fragments-full.xml')//schema[@name
                     != 'Downward' and @name != 'Forward']"/>
9 10

  <xsl:param name="nexamples" select="15"/>
11 12

  <xsl:template match="/">
13 14
    <xsl:variable name="benchmarks"
                  select="document(//benchmark[@type='xquery' or @type='xslt']/@href)"/>
15 16 17 18 19 20
    <!-- fragments -->
    <xsl:result-document method="text" href="fragments.csv">
      <xsl:text>name,color,entries
</xsl:text>
      <xsl:for-each select="$fragments">
        <xsl:call-template name="fragment">
21
          <xsl:with-param name="f" select="current()"/>
22
          <xsl:with-param name="benchmarks" select="$benchmarks"/>
23 24 25 26 27 28 29 30 31 32
        </xsl:call-template>
        <xsl:text>
</xsl:text>
      </xsl:for-each>      
    </xsl:result-document>
    <!-- matrix -->
    <xsl:result-document method="text" href="matrix.json">
      <xsl:text>[</xsl:text>
      <xsl:for-each select="$fragments">
        <xsl:call-template name="line">
33
          <xsl:with-param name="source" select="current()"/>
34
          <xsl:with-param name="benchmarks" select="$benchmarks"/>
35 36 37 38 39 40 41 42 43
        </xsl:call-template>
      </xsl:for-each>
      <xsl:text>]</xsl:text>
    </xsl:result-document>
  </xsl:template>

  <!-- one line of the matrix -->
  <xsl:template name="line">
    <xsl:param name="source"/>
44
    <xsl:param name="benchmarks"/>
45 46 47 48
    <xsl:text>[</xsl:text>
    <xsl:for-each select="$fragments">
      <xsl:call-template name="entry">
        <xsl:with-param name="source" select="$source"/>
49
        <xsl:with-param name="target" select="current()"/>
50 51
        <xsl:with-param name="benchmarks" select="$benchmarks"/>
        <xsl:with-param name="fragments" select="$fragments"/>
52 53 54
      </xsl:call-template>
    </xsl:for-each>
    <xsl:text>]</xsl:text>
55
    <xsl:if test="$source ne $fragments[last()]">
56 57
      <xsl:text>,</xsl:text>
    </xsl:if>
58 59 60 61 62 63
  </xsl:template>

  <!-- one entry of the matrix -->
  <xsl:template name="entry">
    <xsl:param name="source"/>
    <xsl:param name="target"/>
64 65 66
    <xsl:param name="benchmarks"/>
    <xsl:param name="fragments"/>
    <xsl:variable name="examples" select="$benchmarks//xpath[schemas/validation[@schema=$source/@file and @valid='yes'] and schemas/validation[@schema=$target/@file and @valid='no']]"/> 
67 68 69
    <xsl:text>{ "z": </xsl:text><xsl:value-of select="count($examples)"/>
    <xsl:if test="$examples">
      <xsl:text>, "examples": [</xsl:text>
Sylvain Schmitz's avatar
Sylvain Schmitz committed
70 71
      <!--xsl:for-each select="$examples[position() &lt;= $nexamples]"-->
      <xsl:for-each select="$examples">
72
        <xsl:text>"</xsl:text><xsl:value-of 
Sylvain Schmitz's avatar
Sylvain Schmitz committed
73
        select="replace(replace(normalize-space(current()/query),'&quot;',&quot;'&quot;),'\\','\\\\')"/>
74
        <xsl:text>"</xsl:text>
Sylvain Schmitz's avatar
Sylvain Schmitz committed
75 76
        <!--xsl:if test="position() != last() and position() &lt; $nexamples"-->
        <xsl:if test="position() != last()">
77 78 79 80 81 82 83 84 85
          <xsl:text>,</xsl:text>
        </xsl:if>
      </xsl:for-each>
      <xsl:text>]</xsl:text>
    </xsl:if>
    <xsl:text> }</xsl:text>
    <xsl:if test="$target != $fragments[last()]">
      <xsl:text>,</xsl:text>
    </xsl:if>
86 87 88 89 90
  </xsl:template>

  <!-- one fragment -->
  <xsl:template name="fragment">
    <xsl:param name="f"/>
91
    <xsl:param name="benchmarks"/>
92 93 94 95
    <xsl:value-of select="$f/@name"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="$f/@color"/>
    <xsl:text>,</xsl:text>
96
    <xsl:value-of select="count($benchmarks//xpath[schemas/validation[@schema=$f/@file and @valid='yes']])"/>
97
  </xsl:template>
Sylvain Schmitz's avatar
Sylvain Schmitz committed
98
</xsl:stylesheet>