0

我的 XSL 不使用参数

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="reportname" />
<xsl:param name="quarter" />
<xsl:param name="menteename" />

<xsl:template match="AllReports" >
<xsl:for-each select="./Report[@Name=$reportname]" >
    <table border="0" class="dottedlines" cellpadding="2" cellspacing="0">

    <xsl:for-each select="Record[@Period=$quarter] and ($menteename)] >

<tr>
    <xsl:for-each select="Entry">
 <td><xsl:value-of select="." disable-output-escaping="yes"/></td>
               </xsl:for-each>
</tr>

    </xsl:for-each>
</table>

    </xsl:for-each>

    </xsl:template>
</xsl:stylesheet>

我的 XSL 使用硬编码值

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="reportname" />
<xsl:param name="quarter" />
<xsl:param name="menteename" />

<xsl:template match="AllReports" >
<xsl:for-each select="./Report[@Name=$reportname]" >
    <table border="0" class="dottedlines" cellpadding="2" cellspacing="0">

    <xsl:for-each select="Record[@Period=$quarter] and (Entry= 'Dhirde, Govinda' or Entry= 'Vaze, Kedar')] >

<tr>
    <xsl:for-each select="Entry">
 <td><xsl:value-of select="." disable-output-escaping="yes"/></td>
               </xsl:for-each>
</tr>

    </xsl:for-each>
</table>

    </xsl:for-each>

    </xsl:template>
</xsl:stylesheet>

我正在传递变量 $menteename = "Entry= 'Dhirde, Govinda' 或 Entry= 'Vaze, Kedar'" 的值。但是硬编码的东西效果很好,而不是参数一。我发现 XSL 解析存在一些问题,它读取参数值中的标签。这是造成问题的原因吗。我怎样才能使这项工作?

4

2 回答 2

0

变量保存值,而不是表达式。您不能将表达式 lilke (@x = 3) 替换为值为字符串“@x = 3”的变量。要执行此类操作,您需要一个扩展来评估作为字符串提供的 XPath 表达式,例如 saxon:evaluate(),或在 XSLT 3.0 中为 xsl:evaluate。

于 2013-02-22T13:34:10.477 回答
0

好吧,我们确实需要知道您将哪种类型的参数值以及您传递给样式表的值,特别是当您的问题被标记为xslt-2.0您应该可以在哪里传递纯字符串值以及一系列字符串时。

假设您传入一系列字符串'Dhirde, Govinda', 'Vaze, Kedar',您可以简单地测试

  Entry = $menteename

在你的谓词中。

如果您传入一个包含多个名称的纯字符串,那么当然需要将这些字符串拆分为单独的值。由于值已经包含逗号,因此需要不同的分隔符,例如传入的字符串值是'Dhirde, Govinda|Vaze, Kedar',您可以使用

Entry = tokenize($menteename, '\|')

在你的谓词中。

假设您使用 XSLT 1.0 并且不能使用或不想使用扩展函数来拆分参数的字符串值,您可以使用类似的检查

contains(concat('|', $menteename, '|'), concat('|', Entry, '|'))

这假设Entry元素包含单个值,例如Vaze, Kedar,您传入一个bar单独的名称列表,例如 'Dhirde, Govinda|Vaze, Kedar'作为参数值,然后检查

contains('|Dhirde, Govinda|Vaze, Kedar|', '|Vaze, Kedar|')
于 2013-02-22T10:58:46.127 回答