xslt 2.0如何替换$转义美元(转换为LaTeX) [英] xslt 2.0 how replace $ by escaped dollar (for conversion to LaTeX)

查看:210
本文介绍了xslt 2.0如何替换$转义美元(转换为LaTeX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是XSLT的新手。我很广泛地搜索,但是无法弄清楚如何执行以下操作:



我将XML转换为LaTeX。当然,LaTeX需要转义诸如$和#之类的字符。我在替换功能中尝试过以下操作,但它不起作用。 (他们在没有替换功能的情况下工作。)

 < 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>

要转义的可能内容是:
本地定义的字段#931或
本地定义的子字段$ b



我做错了什么?
非常感谢您的答案!

解决方案

如果您要替换一个美元符号 $输入中的 \ $ 的输入中,然后使用 replace(xyz:headline,'\ $' '\\\ $')



如果有几个字符需要相同的转义,那么替换(xyz:headline,'([$#])','\\ $ 1')应该做。



http://xsltransform.net/bdxtqX/1


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!

解决方案

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

这篇关于xslt 2.0如何替换$转义美元(转换为LaTeX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆