Разные таблицы и больше CSS

0

Я должен адаптировать XML и XSL файл. Обычно CSS был только для одной таблицы в моем XSL, но я хочу иметь разные классы таблиц, чтобы изменить их внешний вид.

В моем XML файле я вызываю таблицы:

<table class="first">....

<table class="second">....

Таблицы май:

<component><section>

В моем CSS в XLS я предопределен для всех таблиц:

.section_table {
  width: 100%;
}

.section_table tr td {
     margin-top: 0;
     margin-bottom: 0;
}

Как я могу адаптировать этот код, чтобы мои таблицы выглядели по-другому?

Я также нашел этот код в своем XSL файле, что может быть важно для вас:

<xsl:template match="n1:table/@*|n1:thead/@*|n1:tfoot/@*|n1:tbody/@*|n1:colgroup/@*|n1:col/@*|n1:tr/@*|n1:th/@*|n1:td/@*">
    <xsl:copy>
    <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="n1:table">
  <xsl:variable name="numColumns">
        <xsl:value-of select="count(n1:thead/n1:tr/n1:th)"/>
    </xsl:variable>
    <table class="section_table" cellspacing="0" cellpadding="0"><!--  numColumns="{$numColumns}" -->
    <xsl:apply-templates>
      <xsl:with-param name="numColumns" select="$numColumns" />
    </xsl:apply-templates>
    </table> 
  </xsl:template>
  <xsl:template match="n1:thead">
    <thead>
      <xsl:apply-templates/>
    </thead>
  </xsl:template>
  <xsl:template match="n1:tfoot">
  <xsl:param name="numColumns"/>
    <tfoot>
        <xsl:apply-templates>
      <xsl:with-param name="numColumns" select="$numColumns" />
    </xsl:apply-templates>
    </tfoot>
  </xsl:template>
  <xsl:template match="n1:tbody">
    <tbody>
      <xsl:apply-templates/>
    </tbody>
  </xsl:template>
  <xsl:template match="n1:colgroup">
    <colgroup>
      <xsl:apply-templates/>
    </colgroup>
  </xsl:template>
  <xsl:template match="n1:col">
    <col>
      <xsl:apply-templates/>
    </col>
  </xsl:template>
  <xsl:template match="n1:tr[position() mod 2 = 1]">
  <xsl:param name="numColumns"/>
    <tr class="odd">
    <xsl:apply-templates>
      <xsl:with-param name="numColumns" select="$numColumns" />
    </xsl:apply-templates>
    </tr>
  </xsl:template>
  <xsl:template match="n1:tr">
    <xsl:param name="numColumns"/>
    <tr class="even">
    <xsl:apply-templates>
      <xsl:with-param name="numColumns" select="$numColumns" />
    </xsl:apply-templates>
    </tr>
  </xsl:template>

  <!-- table-heading processing -->
  <xsl:template match="n1:th">

   <!-- sum up all given widths -->
   <xsl:variable name="sum">
     <xsl:call-template name="sumgivenwidths">
       <xsl:with-param name="widths" select="../n1:th" />
     </xsl:call-template>
   </xsl:variable>

   <!-- calculate table width -->
   <xsl:variable name="tablewidth">
     <xsl:call-template name="calctablewidth">
       <xsl:with-param name="widths" select="../n1:th" />
       <xsl:with-param name="sumgivenwidths" select="$sum" />
     </xsl:call-template>
   </xsl:variable>

    <!-- width calculating -->
    <xsl:variable name="cwidth">
      <xsl:choose>
         <xsl:when test="@styleCode != ''">
      <xsl:choose>
        <xsl:when test="substring-after(@styleCode, ':') &lt; 0">
          <xsl:value-of select="substring-after(@styleCode, ':-')" />
        </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="substring-after(@styleCode, ':')" /> 
            </xsl:otherwise>
      </xsl:choose>

        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="(100 - $sum) div count(../n1:th[not(@styleCode != '')])" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <!-- 100 percent scaling -->
    <xsl:variable name="scalewidth" select="concat($cwidth * 100 div $tablewidth, '%')" />

    <!-- create th element -->
    <xsl:element name="th">
      <xsl:attribute name="width"><xsl:value-of select="$scalewidth"/></xsl:attribute>
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

  <!-- recursive loop through all given widths -->
  <xsl:template name="sumgivenwidths">
    <xsl:param name="widths" />
    <xsl:param name="sum" select="0" />

    <xsl:variable name="current" select="$widths[1]" />
    <xsl:variable name="next" select="$widths[position()>1]" />
    <xsl:variable name="currentwidth">
      <xsl:choose>
        <xsl:when test="substring-after($current/@styleCode,'xELGA_colw:') != ''">
          <!-- absolute value -->
          <xsl:choose>
        <xsl:when test="substring-after($current/@styleCode, 'xELGA_colw:') &lt; 0">
          <xsl:value-of select="substring-after($current/@styleCode, 'xELGA_colw:') * -1" />
            </xsl:when>
            <xsl:otherwise>
          <xsl:value-of select="substring-after($current/@styleCode, 'xELGA_colw:')" />
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise> 
      </xsl:choose>
    </xsl:variable>

    <xsl:choose>
      <xsl:when test="not($next)">
        <xsl:value-of select="$currentwidth + $sum" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="sumgivenwidths">
          <xsl:with-param name="widths" select="$next" />
          <xsl:with-param name="sum" select="$currentwidth + $sum" />
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- recursive calculation of table width -->
  <xsl:template name="calctablewidth">
    <xsl:param name="widths" />
    <xsl:param name="sumgivenwidths" />
    <xsl:param name="sum" select="0" />

    <xsl:variable name="current" select="$widths[1]" />
    <xsl:variable name="next" select="$widths[position()>1]" />
    <xsl:variable name="currentwidth">
      <xsl:choose>
        <xsl:when test="substring-after($current/@styleCode, 'xELGA_colw:') != ''">
          <!-- absolute value -->
          <xsl:choose>
            <xsl:when test="substring-after($current/@styleCode, 'xELGA_colw:') &lt; 0">
              <xsl:value-of select="substring-after($current/@styleCode, 'xELGA_colw:') * -1" />              
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="substring-after($current/@styleCode, 'xELGA_colw:')" />
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="(100 - $sumgivenwidths) div count(../n1:th[not(@styleCode != '')])" />
        </xsl:otherwise> 
      </xsl:choose>
    </xsl:variable>

    <xsl:choose>
      <xsl:when test="not($next)">
        <xsl:value-of select="$currentwidth + $sum" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="calctablewidth">
          <xsl:with-param name="widths" select="$next" />
          <xsl:with-param name="sumgivenwidths" select="$sumgivenwidths" />
          <xsl:with-param name="sum" select="$currentwidth + $sum" />
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="n1:td">
  <!-- td-element ELGA stylecode processing -->
    <xsl:variable name="transform_smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
    <xsl:variable name="transform_uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

    <xsl:variable name="transformed_stylecode" select="translate(@styleCode, $transform_smallcase, $transform_uppercase)" />

    <xsl:variable name="tdStyleCode_Style">
      <xsl:if test="contains($transformed_stylecode, 'LRULE')">
        <xsl:text>text-align: left;</xsl:text>
      </xsl:if>
      <xsl:if test="contains($transformed_stylecode, 'RRULE')">
        <xsl:text>text-align: right;</xsl:text>
      </xsl:if>
      <xsl:if test="contains($transformed_stylecode, 'TOPRULE')">
        <xsl:text>vertical-align: top;</xsl:text>
      </xsl:if>
      <xsl:if test="contains($transformed_stylecode, 'BOTRULE')">
        <xsl:text>vertical-align: bottom;</xsl:text>
      </xsl:if>
      <xsl:if test="contains($transformed_stylecode, 'BOLD')">
        <xsl:text>font-weight: bold;</xsl:text>
      </xsl:if>
      <xsl:if test="contains($transformed_stylecode, 'UNDERLINE')">
        <xsl:text>text-decoration: underline</xsl:text>
      </xsl:if>
      <xsl:if test="contains($transformed_stylecode, 'ITALICS')">
        <xsl:text>font-style: italic;</xsl:text>
      </xsl:if>
    </xsl:variable>
    <xsl:variable name="tdStyleCode_Class">
      <xsl:if test="contains($transformed_stylecode, 'EMPHASIS')">
        <xsl:text> smallcaps </xsl:text>
      </xsl:if>    
      <xsl:if test="contains($transformed_stylecode, 'XELGA_BLUE')">
        <xsl:text> xblue </xsl:text>
      </xsl:if>
      <xsl:if test="contains($transformed_stylecode, 'XELGA_RED')">
        <xsl:text> xred </xsl:text>
      </xsl:if>
    </xsl:variable>
    <td style="{$tdStyleCode_Style}" class="{$tdStyleCode_Class}">
      <xsl:apply-templates/>
    </td>
  </xsl:template>
  <xsl:template match="n1:tfoot/*/n1:td">
  <xsl:param name="numColumns"/>
    <td colspan="{$numColumns}">
      <xsl:apply-templates/>
    </td>
  </xsl:template>
  <xsl:template match="n1:table/n1:caption">
    <span class="caption">
      <xsl:apply-templates/>
    </span>
  </xsl:template>
  • 1
    Ваш CSS не связан с вашим примером HTML (или XML), и вы упоминаете XSL три раза, но не публикуете XSL-код. Пожалуйста, отредактируйте свой вопрос и объясните свою проблему более подробно, а также с большим количеством кода.
  • 0
    Важно только мои XML (HTML) и CSS (в XSL). Какой код XSL вы хотите увидеть?
Теги:
html-table
xslt

1 ответ

0

Вам нужно добавить ссылку на файл css в разделе head (html part) в файле xsl

<xsl:template match="/">
    <html>
        <head>
            <link rel="stylesheet" type="text/css" href="my_style.css"/>
        </head>
    </html>
    .
    .
    .
</xsl:tempelate>

Добавить в css файл "my_style.css"

.first {
  width: 100%;
}

.second tr td {
     margin-top: 0;
     margin-bottom: 0;
}

Я добавил файл.

Попробуйте отредактировать свои файлы следующим образом.

  • 0
    привет, спасибо, но это правильно связано :) Мне просто нужна помощь, чтобы сделать операторы CSS для таблиц классов. Меня смущает, что предопределенная таблица css начинается с ".section_table". Как мне начать свои операторы CSS для моих двух классов таблиц?
  • 0
    Я пробовал код, как вы, но он не будет работать :(
Показать ещё 3 комментария

Ещё вопросы

Сообщество Overcoder
Наверх
Меню