我怎样才能减少“何时”? XSLT 中的声明
您好,我正在编写一个 XSLT 语句,其中我需要实现 1500 个条件语句,例如 -
<xsl:when test="ID = '51'">
<br>
<xsl:text>background: url('rightcolumn_seniorliv.jpg') no-repeat;</xsl:text>
<br>
</xsl:when>
<br>
<xsl:when test="ID = '52'">
<br>
<xsl:text>background: url('rightcolumn_seniorliv.jpg') no-repeat;</xsl:text>
<br>
</xsl:when>
如果我像这样编写语句,那么我的页面将会非常慢。我怎样才能减少我的代码并以聪明的方式编写这个语句?
Hello I am writing a XSLT statement where I need to implement 1500 conditional statements like -
<xsl:when test="ID = '51'">
<br>
<xsl:text>background: url('rightcolumn_seniorliv.jpg') no-repeat;</xsl:text>
<br>
</xsl:when>
<br>
<xsl:when test="ID = '52'">
<br>
<xsl:text>background: url('rightcolumn_seniorliv.jpg') no-repeat;</xsl:text>
<br>
</xsl:when>
If i write statement like this way then my pages will be very slow. How can i reduce my code and write this statement in a smart way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 XSLT 2.0,但可以适应 1.0。
This is XSLT 2.0 but can be adapted to work with 1.0.
我看不到您的所有案例,但如果您的前两个案例继续存在,并且您希望 ID 51 到 1551 具有相同的“rightcolumn_seniorliv.jpg”,那么
听起来这些 ID 案例远远超出了逻辑范围,进入了数据领域。我显然对你的应用程序一无所知,但也许某个地方(可能是数据库)的 ID 到图像名称映射是合适的。根据生成 XML 文件的进程(第一个进程,在 XSLT 转换之前),您可能只想通过此映射显式设置图像名称(或缺少图像名称)。然后一起失去
when
I can't see all your cases, but if the pattern from your first two continues and you want that same 'rightcolumn_seniorliv.jpg' for IDs 51 thru 1551 then
it sounds like these ID cases are going well beyond logic and into the data realm. i obviously dont know anything about your app, but perhaps an ID to imagename mapping somewhere (probably database) would be in order. depending on what process generates the XML file (the first one, before XSLT transformation), you might want to just set the image name (or lack thereof) explicitly thru this mapping. then lose the
when
all together