我想在输出属性中包含撇号

I would like to include apostrophe in the output attributes

我写了一个代码,用一个函数来清除所有的特殊字符。

<xsl:function name="lancet:stripSpecialChars">
<xsl:param name="string" />
<xsl:variable name="AllowedSymbols" 
select="'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'"/>
<xsl:value-of select="
translate(
$string,
translate($string, $AllowedSymbols, ' '),
' ')
"/>
</xsl:function> 

<xsd:element xtt:fixedLength="14" xtt:required="true" xtt:severity="error" xtt:align="left">
            <xsl:value-of select="lancet:stripSpecialChars(upper-case(replace(normalize-unicode(translate($emp/wd:First_Name, ',', ' '), 'NFKD'), '⁄', '/')))"/>
        </xsd:element>

现在要求我包含撇号 (')。当我尝试在 AllowedSymbols 中包含相同内容时,出现错误。

现在的输出是D AGOSTINO。我需要像 D'AGOSTINO.

这样的东西

不确定如何处理。有人可以帮我解决这个问题吗?谢谢

你没有说明错误是什么,但你可能只需要转义变量中的撇号。

这是通过将撇号加倍来完成的:

<xsl:variable name="AllowedSymbols" select="'''ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'"/>

由于您使用的是 XSLT 2.0,因此您应该能够使用 replace() 而不是 translate()...

<xsl:function name="lancet:stripSpecialChars">
  <xsl:param name="string"/>
  <xsl:value-of select="replace($string,'[^A-Z0-9'']','')"/>
</xsl:function>

我不会替换小写字母,因为您传递的字符串已经强制为大写,但如果您在其他地方使用该函数,您可以将 a-z 添加到字符 class。

  • 将其编码为 &apos;&#8217; 也)
  • 将值包含在 CDATA 部分中(建议您摆脱编码问题。

<data><![CDATA[some stuff including D'Agostino & other reserved/problematic characters :-) ]]></data>