不带花括号的 Sitecore 项目指南
从 xslt 中的 Sitecore 项 @id 输出中删除/替换 {}
字符的最佳方法是什么?
问题: 我必须从 id 属性中识别 html 中的某些标签。使用名称很危险,因为 Sitecore 最终用户存在在名称中输入空格或非法字符的风险。
另一方面,使用项目 id 会导致 html 中的 id 为:id="{xxxxxxxx-xxx(...)}
,在这种情况下 {}
作为 html id 属性中的字符是非法的
。 从 xslt @id 输出中删除/替换 {}
字符的最佳方法是什么?
What is the best way to strip/replace the {}
characters from the Sitecore item @id output in xslt?
Problem:
I have to identity certain tags in my html from the id
attribute. Using names is dangerous because of the risk of the Sitecore end user typing spaces or illegal characters in the name.
On the other hand using the item id causes the id in the html to say: id="{xxxxxxxx-xxx(...)}
, in which case the {}
are illegal as characters in html id attribute.
So:
What is the best way to strip/replace the {}
characters from the xslt @id output?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不熟悉 Sitecore,但对于 XSLT/XPath,表达式
translate(@id, '{}', '')
应该足以从 id 属性值中删除任何大括号。但要小心使用属性值模板的任何 XSLT 代码,因为其中的花括号具有特殊含义。因此
是安全的,因为select
属性不安全被视为属性值模板。I am not familiar with Sitecore but with XSLT/XPath the expression
translate(@id, '{}', '')
should suffice to remove any curly braces from the id attribute value. Be careful however with any XSLT code using attribute value templates as there the curly braces have a special meaning. So<xsl:value-of select="translate(@id, '{}', '')"/>
is safe as theselect
attribute is not treated as an attribute value template.正确的方法是使用 NormalizeGuid。
我之前(在 Sitecore V5 上)使用过 MainUtils 中的 NormalizeGuid 方法。
我刚刚在 Sitecore 6.2 上进行了测试,但它正在崩溃,因为有 2 个相同的方法名称。这会导致
XslTransformException
您使用的是哪个版本的 Sitecore?我建议尝试 NormalizeGuid:
Goes 类似:
Web.Config
XSLT
,
如果您获得 RTE,则可以使用自定义包装类来修复它。 看看这篇文章。
实际上,我认为您可以使用 MainUtil 中的
GenerateShortID()
来解决这个问题。Right way to do this would be with NormalizeGuid.
I have used before (on Sitecore V5) NormalizeGuid Method from MainUtils.
I just tested on Sitecore 6.2 but it is breaking because there are 2 same method names. This results in an
XslTransformException
Which version of Sitecore you are using? I suggest trying out NormalizeGuid:
Goes something like:
Web.Config
XSLT
and
If you get RTE it is possible to fix it with a custom wrapper class. Take a look this post.
Actually, I think you can get around this by using
GenerateShortID()
it's also in MainUtil.谢谢马丁,使用
translate()
函数帮助了我,但你的答案并不完整。据我了解,问题是关于在 HTML 中剥离尖括号内的大括号,不幸的是,这里
不起作用。考虑这个(非法)代码:
相反,使用这个:
Thanks Martin, using the
translate()
function helped me out, but your answer is not complete.The question - as I understand it - was concerning stripping curly braces inside angle braces in HTML, and here
<xsl:value-of select="..."/>
unfortunately wont work.Consider this (illegal) code:
Instead, use this:
您可以这样做以仅包含连字符:
或者您可以使用以下格式:
You can do it like this to include only the hyphens:
Alternatively you can use the following formats: