XSLT:将Excel文本颜色参数传递给模板 [英] XSLT: Passing Excel text color parameter to templates

查看:52
本文介绍了XSLT:将Excel文本颜色参数传递给模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个让我完全困惑.我有一个多文本颜色单元格.大多数数据是以一种或另一种方式共享的,因此我想使用模板来完成大部分工作.为此,我试图将文本颜色作为参数传递给模板.一个超级简单的例子:

This one has left me completely confused. I have a multi text color cell. Most of the data is shared in one way or another so I wanted to use templates to do most of work. To do that I sought to pass the text color as a parameter to the template. A super simple example:

<xsl:variable name="textColor">
    <xsl:choose>
        <xsl:when test="$cellColor = 's73'">
            <xsl:text>#FFFFFF</xsl:text>
        </xsl:when>
        <xsl:otherwise>
            <xsl:text>#000000</xsl:text>
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable>

<xsl:call-template name="detailLines">
    <xsl:with-param name="textColor" select="$textColor"/>
</xsl:call-template>

<xsl:template name="detailLines">
    <xsl:param name="textColor"/>
    <!-- Start new line -->
    <xsl:text disable-output-escaping="yes">&amp;#10;</xsl:text>
    <!-- Bunch of stuff after this -->
    <Font html:Color="{$textColor}">
        <xsl:text>[</xsl:text>
    </Font>

通常,我对此没有任何问题,但是当文本颜色似乎没有通过时,我感到非常沮丧.但是,当我调试时,文本颜色正在传递.进一步的调查显示,创建的XML也具有文本颜色,但是Excel不会显示它,而是默认为黑色.

Usually I have no issues out of this, but I was floored when the text color didn't seem to pass. However, when I debug the text color is passing. Further investigation showed that the XML created has the text color as well, but Excel does not display it, but instead defaults to black.

我将Excel命名空间放在通常的位置,甚至试图将它们移动也无助于解决问题.

I've got the Excel namespaces in their usual location and even attempting to move them around doesn't help resolve the issue.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"
            xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl:output method="xml" encoding="UTF-8"/>

任何想法都很棒!我还没有遇到这样的问题,其中变量的作用符合预期,但Excel却没有.

Any ideas would be great! I've not had an issue quite like this where the variable is acting as expected, but Excel is not.

编辑以添加其他信息:

我发现了区别,但不确定如何解释.

I've found a difference, but I'm not sure how to interpret it.

<Font html:Color="#FFFFFF">Two Box</Font>
<Font html:Color="#FFFFFF">]</Font>
<Font html:Color="#FFFFFF" xmlns="urn:schemas-microsoft-com:office:spreadsheet">[</Font>

前两行来自未输入detailLines模板的代码,因此它直接调用cellColor变量.最后一行来自传递变量的模板.命名空间似乎是造成我问题的原因,但我无法理解1)为什么存在该命名空间,以及2)如何使其消失.

The first two lines are from code that does not enter the detailLines template and so it calls the cellColor variable directly. The last line is from the template where the variable is passed. The namespace seems to be causing my issue, but I can't understand 1) why it is there, and 2) how to make it go away.

编辑-处理cellColor注释

EDIT - Addressing cellColor comment

由于多种原因,我无法在此处放置实际代码,但是cellColor变量是在textColor之前计算的.最编辑的是:

I cannot put the actual code here for multiple reasons, but the cellColor variable is calculated just prior to the textColor. At it's most redacted it is:

    <xsl:variable name="cellColor">
        <xsl:choose>
            <xsl:when test="A">
                <xsl:text>s216</xsl:text>
            </xsl:when>
            <xsl:when test="B'">
                <xsl:text>s73</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>s210</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

推荐答案

据我以及评论员Peter Vande Weyer的判断,无法以我尝试的方式传递文本颜色.发生此问题的原因是该颜色格式所在的模板不是主模板,因此xslt处理器正在应用名称空间.命名空间的此应用导致Excel失败,因为在处理器插入它的位置中这不是预期的.目前,唯一的解决方案是在处理此文本格式时不使用单独的模板.

As far as can be determined by myself as well as commenter Peter Vande Weyer there is no way to pass the text color in the manner I am attempting. The issue occurs because the template where this color formatting is located is not the main template so the xslt processor is applying the namespace. This application of the namespace causes Excel to fail as it is not expected in the location that the processor inserts it. The only solution at this juncture is to not use a separate template when handling this text formatting.

这篇关于XSLT:将Excel文本颜色参数传递给模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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