Ampersand,XSLT和LaTeX

时间:2016-03-31 11:12:47

标签: xslt latex ampersand

我正在努力从转型中获得基本的东西 - 实际上是Google Tables到XML,再到LaTeX。我的主要问题是:如何从一端传递到另一端的&符号。

我知道类似的问题已被多次回答,但似乎并不是一个有效的解决方案。 (到目前为止,对我来说最好的帮助是:xslt 2.0 how replace $ by escaped dollar (for conversion to LaTeX)

我们说我有出版社" Simon&舒斯特"在Google表格中。导出后将其导入XML中:

<xml>
  <name>
    <publisher>Simon &amp; Schuster</publisher>
  </name>
</xml>

现在在LaTeX中我准备了一个新命令,以便最小化&符号:

\newcommand{\ampersand}{\&}

当我到达XSLT(2.0)时,它会变得非常棘手:

<xsl:function name="foo:ampersand-replace">
    <xsl:param name="passed-string"/>
    <xsl:value-of select="replace($passed-string, '\&amp', '\\\ampersand')"/>
  </xsl:function>

  <xsl:template match="publisher">
     <xsl:value of select="foo:ampersand-replace(publisher)"/>
  </xsl:template> 

因为这不编译(Saxxon 9.6)。问题当然是Ampersand:不允许语法错误转义字符。

我也尝试了不同的方法:

<xml>
  <name>
    <publisher>Simon <c rendition="#ampersand"/> Schuster</publisher>
  </name>
</xml>

问题在于,我无法使用

<xsl:value-of/>

-command,以及c未处理。 知道我错了吗?

1 个答案:

答案 0 :(得分:1)

我认为您的xsl:function需要看起来像这样:

<xsl:function name="foo:ampersand-replace">
    <xsl:param name="passed-string"/>
    <xsl:value-of select="replace($passed-string, '&amp;', '\\ampersand')"/>
</xsl:function>

另请注意,当您调用它时,您当前的模板与publisher匹配,因此您可以对此进行定位,因此对该函数的调用应如下所示...

<xsl:template match="publisher">
    <xsl:value-of select="foo:ampersand-replace(.)"/>
</xsl:template> 
相关问题