xslt 2.0 how replace $ by escaped dollar (for conversion to LaTeX)

让人想犯罪 __ 提交于 2020-01-05 02:58:25

问题


I am new to XSLT. I googled extensively but couldn't figure out how to do the following:

I am transforming XML to LaTeX. Of course, LaTeX needs to escape characters such as $ and #. I tried the following in the replace function but it does not work. (They do work without the replace function.)

<xsl:template match="xyz:doc">
\subsubsection{<xsl:value-of select="replace( xyz:headline, '(\$)', '\$1' )"/>}  
...
</xsl:template>

<xsl:template match="xyz:doc">
\subsubsection{<xsl:value-of select="replace( xyz:headline, '\$', '\$' )"/>}  
...
</xsl:template>

Possible content to be escaped is: "Locally defined field #931" or "Locally defined subfield $b"

What am I doing wrong? Many thanks for your answers!


回答1:


If you want to replace a dollar symbol $ in the input with \$ in the output then use replace(xyz:headline, '\$', '\\\$').

If there are several characters that need the same escaping then replace(xyz:headline, '([$#])', '\\$1') should do.

Sample at http://xsltransform.net/bdxtqX/1



来源:https://stackoverflow.com/questions/31592977/xslt-2-0-how-replace-by-escaped-dollar-for-conversion-to-latex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!