XSLT 参数不起作用
我在 Java 中使用 XSLT 转换器。我确信问题出在我输入 XSLT 语法的方式上。
基本上,我必须查看 XML 节点之一中的属性“id”是否相当于一个值,XSL 应该处理一个模板。我需要将此测试值作为 xsl:param 传递。当我在静态值上测试它时,它工作得很酷:
<ul class="levelOneNav">
<xsl:for-each select="level1[@id='sub-page-1']">
<xsl:call-template name="level1"/>
</xsl:for-each>
<div class="clear"></div>
</ul>
测试部分位于上面的第二行。 AFAIK 在字符串中放入参数,格式为
其中 $ContentID
是声明为
的 xsl:param
所以这是我正在键入的代码,
<ul class="levelOneNav">
<xsl:for-each select="level1[@id='$ContentID']">
<xsl:call-template name="level1"/>
</xsl:for-each>
<div class="clear"></div>
</ul>
但它不起作用。我还尝试过使用
它也失败了。
任何建议将不胜感激。如果您觉得我应该学习一些东西,请给我链接。感谢您抽出时间...
I am using a XSLT Transformer in Java. I am sure the problem is in the way I'm typing in the XSLT syntax.
Basically, I have to see if an attribute 'id' in one of the nodes of XML is equivalent to a value, the XSL should process a template. I need to pass this test value as a xsl:param. When I test it on a static value, it works cool:
<ul class="levelOneNav">
<xsl:for-each select="level1[@id='sub-page-1']">
<xsl:call-template name="level1"/>
</xsl:for-each>
<div class="clear"></div>
</ul>
The testing portion is in second line above. AFAIK to put in a param inside the strings, the format is <xsl:for-each select="level1[@id='$ContentID']">
in which $ContentID
is the xsl:param declared as <xsl:param name="ContentID"/>
So this is the code I'm keying in
<ul class="levelOneNav">
<xsl:for-each select="level1[@id='$ContentID']">
<xsl:call-template name="level1"/>
</xsl:for-each>
<div class="clear"></div>
</ul>
but it doesn't work. I've also tried using <xsl:for-each select="level1[@id='{$ContentID}']">
and it also fails.
Any advise is appreciated greatly. Please give me links if you feel I should learn something. Thanks for your time ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,“据我所知”你错了。 XSLT 属性中的某些字符串值当然接受
"{$param}"
语法(注意大括号),但在您的情况下,您所追求的要简单得多:< code>@id=$ContentID编辑:请注意,“{$param}”适用于 XSLT 属性,请参阅示例:
No, that “AFAIK” is where you are wrong. Some string values in XSLT attributes certainly do accept a
"{$param}"
syntax (note the braces), but in your case what you are after is much simpler:@id=$ContentID
EDIT: Note that the '{$param}' applies for XSLT attributes, see example:
尝试
变量或参数将以同样的方式工作。
请注意,您必须删除
$ContentID
周围的简单引号。另外,如果 level1/@id 是唯一的,则不需要 foreach。
下面是一个将变量作为参数发送的示例。
try
variable or param will work same way.
becareful you must remove simple quote around
$ContentID
.another things if
level1/@id
is unique you don't need the foreach.below an exemple to send the variable as param.