未捕获实际元素标记

时间:2010-04-27 14:56:32

标签: xslt-2.0 xslt

我正在使用下面的XSL代码来构建一个在mouseover上调用javascript函数的span标记。 javascipt的输入应该是一个html表。变量“showContent”的输出仅提供文本内容,但不包含表标记。 如何解决这个问题。

XSL:

          <xsl:variable name="aTable" as="element()*">
        <table border="0" cellspacing="0" cellpadding="0">
        <xsl:for-each select="$capturedTags">
        <tr><td><xsl:value-of select="node()" /></td></tr>
        </xsl:for-each>
        </table>
        </xsl:variable>
        <xsl:variable name="start" select='concat("Tip(&#39;", "")'></xsl:variable>
        <xsl:variable name="end" select='concat("&#39;)", "")'></xsl:variable>
        <xsl:variable name="showContent">
                <xsl:value-of select='concat($start,$aTable,$end)'/> 
        </xsl:variable>
        <span xmlns="http://www.w3.org/1999/xhtml" onmouseout="{$hideContent}" 
              onmouseover="{$showContent}" id="{$textNodeId}"><xsl:value-of select="$textNode"></xsl:value-of></span>

实际输出: <span onmouseout="UnTip()" onmouseover="Tip('content1')" id="d1t14"&gt;是</span&gt;

预期产出:

   <span onmouseout="UnTip()" onmouseover="Tip('<table><tr><td>content1</td></tr>')" id="d1t14">is my </span>

上述XSL需要对表,tr和td标记进行哪些更改才能传递?

1 个答案:

答案 0 :(得分:2)

concat()函数获取其参数的字符串值并连接它们。

定义的

$aTable没有字符串值。

您可能希望将其定义为element()*,而不是xs:string

然后您需要转义其中的文本,或将其包含在CDATA标记中。由于$aTable的值是动态生成的,因此无法使用CDATA

您需要自己的XML序列化处理才能将所有标记标记转换为文本。即使在这种情况下,由于属性值规范化,onmouseover属性的内容也将包含转义字符。

似乎很不可能。