2013-02-22 85 views
0

我的XSL不带参数的工作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的值=“输入= 'Dhirde,Govinda'或Entry ='Vaze,Kedar'“。但硬编码的东西效果不是参数之一。我发现XSL解析存在一些问题,它读取参数值中的标记。这是否导致问题。我该如何做这项工作?

+0

抱歉,上传代码我输入了一个关闭']'额外。它不适用于并与 Govinda 2013-02-22 10:05:01

回答

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|') 
+0

那么我的建议是XPath/XSLT 2.0,您需要使用像Saxon 9或AltovaXML或XmlPrime这样的XSLT 2.0处理器。这个错误信息听起来好像你在只支持XSLT 1.0的Firefox这样的Mozilla浏览器中使用XSLT。因此,您首先需要分别说明哪个XSLT处理器分别使用哪个XSLT版本。 – 2013-02-22 11:34:56

+0

我正在使用XSLT 1.0。你能帮我解决一下 – Govinda 2013-02-22 12:23:55

+0

对于XSLT 1.0,你有两个选择,如果你的XSLT处理器支持一个,或者使用像'contains(concat('|',$ menteename,'|')这样的检查,项)'。我将编辑我的帖子,并在帖子中显示此评论。 – 2013-02-22 14:09:14

0

变量保存值,而不是表达式。您不能用值为字符串“@x = 3”的变量替换表达式lilke(@x = 3)。为了做到这一点,您需要一个扩展来评估以字符串形式提供的XPath表达式,例如saxon:evaluate()或XSLT 3.0 xsl:evaluate。