2016-03-31 70 views
0

我正在從一個基本的轉變中掙扎 - 從實際上Google Tables到XML到LaTeX。我的主要問題是:如何通過&符號從一端傳遞到另一端。&符號,XSLT和LaTeX

我知道類似的問題已經被回答了幾次,但似乎沒有一個可行的解決方案。 (到目前爲止最好的幫助似乎是這樣的:xslt 2.0 how replace $ by escaped dollar (for conversion to LaTeX)

假設我在Google Tables中有出版社「Simon & Schuster」。之後我導出和導入到XML是:

<xml> 
    <name> 
    <publisher>Simon &amp; Schuster</publisher> 
    </name> 
</xml> 
在乳膠

現在我準備了一個新的命令,以便最小化符號-問題:

\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)。問題當然是&符號:語法錯誤轉義字符不允許。

我嘗試了不同的方法,也:

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

的問題存在,隨着c不是我不能使用

<xsl:value-of/> 

-command,以及處理。 任何想法我錯了什麼?

回答

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>