如何在XSL文件中的ID后面附加数字 [英] How to append a number to an ID inside an XSL file

查看:135
本文介绍了如何在XSL文件中的ID后面附加数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下XSL文件,该文件将重复多次(以我的情况为4次):

I have the following XSL file which will be repeated many times (in my case 4 times):

<xsl:if test="Html/root/lcGroup/txtCity != ''">
    <div id="labOCSign" class="tableHeading"></div>
    <h4>
        <span id="spnCity">
            <xsl:value-of select="Html/root/lcGroup/txtCity" />
        </span>
        <xsl:if test="Html/root/lcGroup/txtZip != ''">
            <xsl:text>, </xsl:text>
            <xsl:value-of select="Html/root/lcGroup/dlState" />
            <xsl:text>&#160;</xsl:text>
            <xsl:value-of select="Html/root/lcGroup/txtZip" />
        </xsl:if>
    </h4>
</xsl:if>

CSS:

.tableHeading
{
    background: #E5E5E5 url("../theImages/recommendationBadge.png") top left no-repeat;
    padding-top: 60px;
    padding-bottom: 25px;
}
.tableHeading2
{
    background: #E5E5E5 url("../theImages/recommendationBadge2.png") top left no-repeat;
    padding-top: 60px;
    padding-bottom: 25px;
}

我有以下JQuery它将替换labOCSign的类:

I have the following JQuery which will replace class of the labOCSign:

var cityName = $(".spnCity").text();
var weekDay = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][(new Date()).getDay()];

if (cityName.toLowerCase() == "rye") {
    if (weekDay == "Monday" || weekDay == "Wednesday" || weekDay == "Friday") {
        if (validNow("08:00AM", "5:30PM")) {
            $("#labOCSign").removeClass("tableHeading2").addClass("tableHeading");
        }
        else {
            $("#labOCSign").removeClass("tableHeading").addClass("tableHeading2");
        }
    }
}
else if (cityName.toLowerCase() == "new roc") {
    if (weekDay == "Monday" || weekDay == "Wednesday" || weekDay == "Friday") {
        if (validNow("08:00AM", "5:30PM")) {
            $("#labOCSign").removeClass("tableHeading2").addClass("tableHeading");
        }
        else {
            $("#labOCSign").removeClass("tableHeading").addClass("tableHeading2");
        }
    }
}

我现在遇到的问题是脚本只需要一个实例.

The issue I have now is the script only takes one instance.

如何在spanCity之后添加数字以确保它们在XSL文件中都是唯一的?

How can I add a number after spanCity to ensure they are all unique in the XSL file?

因此,它将是#spnCity1,#spnCity2,#spnCity3,#spnCity4 ...

So, it will be #spnCity1, #spnCity2, #spnCity3, #spnCity4...

推荐答案

如果提供的XSLT部分例如在<xsl:for-each>循环中,可以使用position()来获取递增值(循环中的当前位置)和concat():

In case the provided XSLT part is e.g. in an <xsl:for-each> loop, you can use position() to get an incremented value (the current position in the loop) and concat():

<span id="concat('spnCity', position())">

更新,因为建议的方法在设置中不起作用:

Update as suggested approach didn't work in the settings:

两种适用的符号是:

<span>
  <xsl:attribute name="id" select="concat('spnCity', position())"/>
</span>

<span>
  <xsl:attribute name="id">
    <xsl:value-of select="concat('spnCity', position())"/> 
  </xsl:attribute>
</span>

可以在属性后添加内容:

The content can just be added after the attribute:

<span>
  <xsl:attribute name="id">
    <xsl:value-of select="concat('spnCity', position())"/> 
  </xsl:attribute>
  <xsl:value-of select="Html/root/lcGroup/txtCity" />
</span>

只需创建两个版本的演示.

这篇关于如何在XSL文件中的ID后面附加数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆