Как я могу вставить новые теги вокруг таблицы в HTML с определенным классом, используя XSLT? - PullRequest
0 голосов
/ 21 апреля 2020

Я почти ничего не знаю о XSLT и должен решить сложную проблему. Наше программное обеспечение для составления электронной почты производит HTML примерно так:

<body style="background-color:#F2F2F2">
<table width="100%" cellpadding="0" cellspacing="0" bgcolor="#F2F2F2"><tr><td align="center" bgcolor="#F2F2F2">
<table cellpadding="0" cellspacing="0" width="138" role="presentation" bgcolor="#FFFFFF" 
style="border-collapse: collapse; table-layout: fixed" class="EX_RESPONSIVE_TABLE_768"><tr><td 
class="EX_RESPONSIVE_HIDE_CELL_768" width="138" height="0"></td>
</tr>
<tr><td class="EX_RESPONSIVE_HIDE_CELL_768" valign="middle" align="center"><table 
id="ex-table1" cellpadding="0" cellspacing="0" width="138" style="border-collapse: collapse"><tr><td 
width="138" style="margin-bottom: 0px; margin-top: 0px; padding-top:5.00px; padding-bottom:5.00px" 
align="center" valign="top"><table cellpadding="0" cellspacing="0" width="100%" 
style="border-collapse: collapse"><tr><td style="margin-top: 0; margin-bottom: 0; font-size: 0; text-align: center; padding-top: 2px; padding-bottom: 2px; line-height: 1"><span 
style="font-family: 'Arial', serif; font-size: 15px; line-height: 17px; color:#000000">Lorem 
Impsum 1</span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr><td class="HideMSO EX_RESPONSIVE_SHOW_CELL_768" valign="middle" align="center"><table 
id="ex-table2" cellpadding="0" cellspacing="0" width="138" style="border-collapse: collapse"><tr><td 
width="138" style="margin-bottom: 0px; margin-top: 0px; padding-top:5.00px; padding-bottom:5.00px" 
align="center" valign="top"><table cellpadding="0" cellspacing="0" width="100%" 
style="border-collapse: collapse"><tr><td style="margin-top: 0; margin-bottom: 0; font-size: 0; text-align: center; padding-top: 2px; padding-bottom: 2px; line-height: 1"><span 
style="font-family: 'Arial', serif; font-size: 15px; line-height: 17px; color:#000000">Lorem 
ipsum 2</span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td></tr></table>
</body>

И нам нужно (для поддержки почтовых клиентов Outlook) изменить его на:

<body style="background-color:#F2F2F2">
<table width="100%" cellpadding="0" cellspacing="0" bgcolor="#F2F2F2"><tr><td align="center" bgcolor="#F2F2F2">
<table cellpadding="0" cellspacing="0" width="138" role="presentation" bgcolor="#FFFFFF" 
style="border-collapse: collapse; table-layout: fixed" class="EX_RESPONSIVE_TABLE_768"><tr><td 
class="EX_RESPONSIVE_HIDE_CELL_768" width="138" height="0"></td>
</tr>
<tr><td class="EX_RESPONSIVE_HIDE_CELL_768" valign="middle" align="center"><table 
id="ex-table1" cellpadding="0" cellspacing="0" width="138" style="border-collapse: collapse"><tr><td 
width="138" style="margin-bottom: 0px; margin-top: 0px; padding-top:5.00px; padding-bottom:5.00px" 
align="center" valign="top"><table cellpadding="0" cellspacing="0" width="100%" 
style="border-collapse: collapse"><tr><td style="margin-top: 0; margin-bottom: 0; font-size: 0; text-align: center; padding-top: 2px; padding-bottom: 2px; line-height: 1"><span 
style="font-family: 'Arial', serif; font-size: 15px; line-height: 17px; color:#000000">Lorem 
Impsum 1</span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<!--[if !mso 9]><!--><tr><td class="HideMSO EX_RESPONSIVE_SHOW_CELL_768" valign="middle" align="center"><table 
id="ex-table2" cellpadding="0" cellspacing="0" width="138" style="border-collapse: collapse"><tr><td 
width="138" style="margin-bottom: 0px; margin-top: 0px; padding-top:5.00px; padding-bottom:5.00px" 
align="center" valign="top"><table cellpadding="0" cellspacing="0" width="100%" 
style="border-collapse: collapse"><tr><td style="margin-top: 0; margin-bottom: 0; font-size: 0; text-align: center; padding-top: 2px; padding-bottom: 2px; line-height: 1"><span 
style="font-family: 'Arial', serif; font-size: 15px; line-height: 17px; color:#000000">Lorem 
ipsum 2</span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><!--<![endif]-->
</table></td></tr></table>
</body>

Я нахожусь на немного потери, если я честен. Я нашел руководства по вставке пар HTML tag + element, но ничего такого, что бы конкретно вставляло эти теги, которые обертывают вокруг комка HTML Из разговора с кем-то я полагаю, что мы можем использовать атрибут класса «hideMSO», чтобы дать XSLT «крючок» для идентификации соответствующего раздела, но после этого я потерян.

Может ли анойн помочь?

1 Ответ

0 голосов
/ 21 апреля 2020

Вы можете попробовать что-то в этом роде:

    <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    version="1.0">

  <xsl:output method="html" indent="yes"/>

  <xsl:template match="tr[td[contains(@class,'HideMSO')]]">
    <xsl:comment>[if !mso 9]&gt;&lt;!</xsl:comment> 
        <xsl:copy>
            <xsl:apply-templates/>
        </xsl:copy>
    <xsl:comment>&lt;![endif]</xsl:comment>
  </xsl:template>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Посмотрите, как это работает здесь: https://xsltfiddle.liberty-development.net/3MvmXiK/1

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...