我正在尝试制作一个网页,允许用户输入搜索 xml 文件。有多个输入,但在提交搜索时我无法容纳空输入。
var date = rDateSearch.value;
if (date === "") {
var datein = "date=*";
}
else {
var datein = "date=" + date";
}
然后将“date”变量发送到 xsl:when
测试。我希望 xsl:when
返回所有日期值。
有办法做到这一点吗?我目前的想法行不通。
这是我的 xml 示例:
<record>
<name>John Smith</name>
<date>1972</date>
<rating>0.5</rating>
</record>
这是我的 xsl。我不确定这段代码的适用性。
<xsl:for-each select="records/record">
<xsl:choose>
<xsl:when test ="name=*">
<xsl:choose>
<xsl:when test ="date=*">
<xsl:choose>
<xsl:when test ="rating=*">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="date"/></td>
<td><xsl:value-of select="rating"/></td>
</tr>
</xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:for-each>
最佳答案
如果用户没有指定一个值来过滤名称、日期或评级,并且您正在尝试找出什么表达式将选择任何/全部,您可以使用:
xsl:when test="date"
只要在 xsl:for-each< 中评估的
.record
元素中有一个 date
元素,就会“通过”测试
或者,您可以使用:
xsl:when test="true()"
无论是否有日期元素,都会评估为 true。
相同的逻辑适用于其他元素。
关于javascript - 默认使用 xsl :when test? 返回所有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43033493/