【发布时间】:2020-08-04 06:49:00
【问题描述】:
我对 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 标记 + 元素对的指南,但没有专门插入这些围绕 HTML 块的标记。我相信通过与某人交谈,我们可以使用“hideMSO”类属性给 XSLT 一个“钩子”来识别相关部分,但在那之后我迷路了。
可以帮忙吗?
【问题讨论】:
-
XSLT 通常的输入是 XML,而不是 HTML。而且您似乎想插入 cmets,而不是标签。
-
这将如何运行?您使用的是哪个 XSLT 引擎?到目前为止,您尝试过什么?
-
@Sebastien - 我相信它是 Xalan,它是 XSLT v1.0。到目前为止,我已经尝试查看 w3schools xslt 课程,但一无所获。似乎没有什么能与我的情况相提并论。我的意思是查看 w3schools 网站,我所看到的课程似乎都没有涵盖这方面的任何部分。有一个插入注释 (
),但我看不到在表格周围应用它的方法。是否有在线教程可以让我学习正确的东西? w3s 教程似乎面向非常不同的应用程序。