xsl文件中的Java验证用于输入字段 [英] Javascript Validation in xsl file for input field
本文介绍了xsl文件中的Java验证用于输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下xsl:
<xsl:template match="attribute[controlType='TextBox']">
<input style="width:180pt" type="input" value="">
<xsl:attribute name="id">fldCsXML_<xsl:value-of select="name"/></xsl:attribute>
<xsl:attribute name="name">fldCsXML_<xsl:value-of select="name"/></xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="data"/></xsl:attribute>
</input>
</xsl:template>
我想对值部分进行javascript验证,以禁止使用符号.仅允许数字或字母.
I want to do javascript validation on the value part to not allow symbols. Just to allow numbers or letters.
也许与jquery类似:
Maybe with jquery similar to :
try bellow script this will not allow special charter # $ % ^ & * ( )
function validate() {
var element = document.getElementById('input-field');
element.value = element.value.replace(/[^a-zA-Z0-9@]+/, '');
};
<input type="text" id="input-field" onkeyup="validate();"/>
感谢以最简单的方式更改上述xsl并添加jquery/javascript验证的任何帮助
Any help in changing the xsl above in the easiest possible way and adding jquery / javascript validation is appreciated
推荐答案
因此您可以执行以下操作:
So you could do something like this:
提供输入文件...
<t>
<attribute>
<controlType>TextBox</controlType>
<name>some-name</name>
<data>some-datum</data>
<id>input-field</id>
<width-on-form>180</width-on-form>
</attribute>
</t>
...正在应用XSLT 2.0样式表...
... applying XSLT 2.0 stylesheet ...
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="html" version="5" encoding="UTF-8" />
<xsl:strip-space elements="*" />
<xsl:template match="/">
<html>
<head>
<title>Some form</title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="t">
<form>
<xsl:apply-templates />
</form>
</xsl:template>
<xsl:template match="attribute[controlType eq 'TextBox']">
<input type="text" id="{id}" name="{name}" style="width:{width-on-form}pt" value="{data}" pattern="[a-zA-Z0-9@]+" />
</xsl:template>
</xsl:transform>
...将产生输出...
... will yield output ...
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Some form</title>
</head>
<body>
<form>
<input
type="text"
id="input-field"
name="some-name"
style="width:180pt"
value="some-datum"
pattern="[a-zA-Z0-9@]+">
</form>
</body>
</html>
这篇关于xsl文件中的Java验证用于输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文