[英]How to split a string with <br> in xml using xslt-1.0
這是 HTML 的一部分,我想使用 XSLT 進行轉換
<tr>
<td>ELE1600A </td>
<td>CIRCUITS ELECTRIQUES <br>Chahe Nerguizian </td>
<td><center>01 </center></td>
<td><center>01 </center></td>
<td><center>03</center></td>
</tr>
我想拆分以下
<td>CIRCUITS ELECTRIQUES <br>Chahe Nerguizian </td>
進入:
我試過使用
<xsl:valuf-of select="substring-before(td[2],'
')"/>
<xsl:valuf-of select="substring-after(td[2],'
')"/>
但它在 php 和 eclipse 的 XSLT 處理器中都沒有返回任何東西給我。 我怎么能做到這一點?
提前致謝。
正如評論中提到的,你這里沒有 XHTML,因此沒有 XML,所以不能在上面使用 XSLT。 然而....如果它被修改為 XML,你可以用它做點什么。
想象一下這是格式良好的起始文檔:
<tr>
<td>ELE1600A </td>
<td>CIRCUITS ELECTRIQUES<br />Chahe Nerguizian
</td>
<td>
<center>01 </center>
</td>
<td>
<center>01 </center>
</td>
<td>
<center>03</center>
</td>
</tr>
然后,您可以使用身份轉換,並使用額外的匹配模板來處理匹配以br元素為子元素的td元素。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="td[br]">
<xsl:copy>
<ol>
<xsl:apply-templates />
</ol>
</xsl:copy>
</xsl:template>
<xsl:template match="td[br]/node()">
<li>
<xsl:call-template name="IdentityTransform" />
</li>
</xsl:template>
<xsl:template match="td[br]/br">
<!-- Ignore tag -->
</xsl:template>
<xsl:template match="@*|node()">
<xsl:call-template name="IdentityTransform" />
</xsl:template>
<xsl:template name="IdentityTransform">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
當這應用於輸入 XML 時,將生成以下內容:
<tr>
<td>ELE1600A </td>
<td>
<ol>
<li>CIRCUITS ELECTRIQUES </li>
<li>Chahe Nerguizian </li>
</ol>
</td>
<td>
<center>01 </center>
</td>
<td>
<center>01 </center>
</td>
<td>
<center>03</center>
</td>
</tr>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.