2016-03-31 9 views
0

私は実際にはGoogle Table to XMLからLaTeXへの変換で何か基本的なことに苦労しています。私の主な問題は、アンパサンドを一方の端から他方の端にどのように通すかです。Ampersand、XSLT、LaTeX

私は同じような質問が数回答えられていることは知っていますが、実際の解決策はないようです。 (これまでのところ最高の助けが私にはこれだと思われます:xslt 2.0 how replace $ by escaped dollar (for conversion to LaTeX)

私は出版社がGoogleのテーブルで "Simon &シュスター"を持っているとしましょう。私はそれをエクスポートして、XMLにインポートした後、それはです:

のLaTeXで今
<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)。もちろん、問題はAmpersand:Syntax Error Escscape文字は使用できません。

は、私も、別のアプローチを試してみました:

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