【问题标题】:Showing True Type Font Personalized xslt 1.0显示 True Type 字体个性化 xslt 1.0
【发布时间】:2013-12-17 15:40:05
【问题描述】:

这是我的 xml:

<SECTION_CONTENT_LIST_ITEM>
    <NTC_LIGHTLISTPRODUCT>
      <IMMUTABLE_ID>9849</IMMUTABLE_ID>
      <LIGHT_STRUCTURE>
        <STRUCTURE_DESCRIPTION>Boa \A a fuso \B segnale \C speciale \D</STRUCTURE_DESCRIPTION>
      </LIGHT_STRUCTURE>
    </NTC_LIGHTLISTPRODUCT>
</SECTION_CONTENT_LIST_ITEM>

将注意力集中在“结构描述”字段上: 你可以看到:“Boa \A a fuso \B segnale \C speciale \D”

根据值 \A,\B,\C,\D,我的 xslt 代码打开一个 true type 字体文件,并将此 \a 或 \b 或 \c 或 \d 转换为特殊的不同字符。

我的 xslt 代码:

<xsl:template name="simboli">
<xsl:param name="testo"/>
<xsl:param name="separatore"/>
<xsl:choose>
        <xsl:when test="contains($testo, $separatore)">
            <xsl:value-of select="substring-before($testo, $separatore)"/>
                <span style="font-family:lol;font-size:9pt;">
                    <xsl:value-of select= "substring(., string-length(substring-before($testo, $separatore)) +2, 1)"/>
                </span>             
                <xsl:call-template name="simboli">
                    <xsl:with-param name="testo" select="substring(substring-after($testo, $separatore), 2, string-length(substring-after($testo, $separatore)))"/>
                    <xsl:with-param name="separatore" select="$separatore"/>                        
                </xsl:call-template>
        </xsl:when>
    <xsl:otherwise>
            <xsl:value-of select="$testo"/>
    </xsl:otherwise>
</xsl:choose>   

你可以看到我使用 font-family=lol

<span style="font-family:lol;font-size:9pt;">
    <xsl:value-of select= "substring(., string-length(substring-before($testo, $separatore)) +2, 1)"/>
</span>

我用 Microsoft Word 打开这个 XML 文件,我选择 Xslt 文件,然后在输出中得到:

Boa A a fuso f segnale u speciale s

字母 f ,u 和 s 应该是 LOL 的特殊字符。

我的问题是:为什么只转换第一个字符?

N.B:我控制 XSLT 并且运行正确,唯一的问题是只转换第一个 \A 并跳转 \B \C \D。

【问题讨论】:

    标签: xml ms-word xslt-1.0


    【解决方案1】:

    你有一个小错误在行

    <xsl:value-of select= "substring(., string-length(substring-before($testo, $separatore)) +2, 1)"/>
    

    在这里你想输出字符串的开头直到分隔符。您使用当前上下文. 来引用整个字符串。这在对模板的初始调用中工作正常。当您递归时,. 仍将指向 initial 字符串,因为显然&lt;xsl:call-template&gt; 不会更改上下文。相反,您想要做的是将作为testo 传递的字符串的子字符串:

    <xsl:value-of select= "substring($testo, string-length(substring-before($testo, $separatore)) +2, 1)"/>
    

    顺便说一句:应该不是

    <xsl:with-param name="testo" select="substring(substring-after($testo, $separatore), 2, string-length(substring-after($testo, $separatore)) - 1)"/>
    

    计算剩余子串的长度?不过,没有-1 的版本似乎可以工作。 :-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-09
      • 2012-04-19
      • 2010-11-08
      • 1970-01-01
      • 2015-01-02
      相关资源
      最近更新 更多