我希望将首字母大写中的标题更改为正确的标题大小写,即文章、连词和选择介词都是小写的。最初我希望使用“停用词”列表的 xml 文档来实现这一点,但我最接近成功的是通过分析字符串中的正则表达式。问题是,作为 xslt 的新手,我不知道在不无限循环的情况下使其递归。此外,理想情况下,这将是一个函数而不是模板。我感谢那里的专家提供的任何帮助。
输入:
<element>
<title>The String Is In First Letter Caps And May Have A Word Or Words Such As A, An, Or The And And, But, For, As, At, In, Or When.</title>
</element>
xslt:
<xsl:template name="proper-case" match="/element/title">
<xsl:param name="title" select="."/>
<xsl:analyze-string select="$title" regex="\WA\W|\WAn\W|\WThe\W|\WAnd\W|\WBut\W|\WFor\W|\WNor\W|\WOr\W|\WFSo\W|\WYet\W|\WAs\W|\WAt\W|\WBy\W|\WIf\W|\WIn\W|\WOf\W|\WOn\W|\WTo\W|\WWith\W" flags="i">
<xsl:matching-substring>
<xsl:value-of select="lower-case(.)"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
电流输出:
<element>
<title>The String Is in First Letter Caps and May Have a Word or Words Such as A, an, or The and And, but, for, as, at, in, or When.</title>
</element>
期望的输出:
<element>
<title>The String Is in First Letter Caps and May Have a Word or Words Such as a, an, or the and and, but, for, as, at, in, or when.</title>
</element>