首页 > 解决方案 > 以 xslt 中的数字开头

问题描述

条目以数字或“中午”一词开头。这些将成为元素。

结尾嵌套样式字符 () 应放置在节目标题的末尾,以空格标记,后跟以下代码之一:MVLSC、16VLSC、MSC、16VL、ML、MC、PGC、16VL

输入 :

<table>
    <tr>
       <td> 7.10    Between Worlds 16VLSC 2018 Thriller. Haunted by memories of his deceased family, a truck.</td>
    </tr>
    <tr>
       <td>A look at the latest movie trailers, coming soon to cinemas.</td>
    </tr>
</table>

输出 :

<p type="Entry"><tab/>7.10<tab/>Between Worlds<char type="endNestedStyleHere"/> 16VLSC 2018 Thriller. Haunted by memories of his deceased family, a truck.</p>

尝试过的代码:

<xsl:template match="td[starts-with(.,'1234567890')]">
    <p>
      <xsl:apply-templates/>
    </p>
</xsl:template>

我正在使用 XSLT 2.0。谢谢

标签: xslt

解决方案


您可以matches在 XSLT 2.0中使用

<xsl:template match="td[matches(., '^[0-9].*')]">
    <p>
      <xsl:apply-templates/>
    </p>
</xsl:template>

或者,如果数字前可能有空格,您也可能需要检查空格...

<xsl:template match="td[matches(., '^\s*[0-9].*')]">
    <p>
      <xsl:apply-templates/>
    </p>
</xsl:template>

请注意,如果您确实需要 XSLT 1.0 解决方案,您可以这样做...

<xsl:template match="td[contains('0123456789', substring(normalize-space(), 1, 1))]">

推荐阅读