簡體   English   中英

xsl文件中的Java驗證用於輸入字段

[英]Javascript Validation in xsl file for input field

我有以下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驗證,以禁止使用符號。 僅允許數字或字母。

也許與jquery類似:

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驗證的任何幫助

因此,您可以執行以下操作:

給定輸入文件...

<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樣式表...

<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>

...將產生輸出...

 <!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> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM