xslt check for alpha numeric character

Posted by Newcoma on Stack Overflow See other posts from Stack Overflow or by Newcoma
Published on 2013-10-30T09:50:23Z Indexed on 2013/10/30 9:54 UTC
Read the original article Hit count: 181

Filed under:
|

I want to check if a string contains only alphanumeric characters OR '.'

This is my code. But it only works if $value matches $allowed-characters exactly. I use xslt 1.0.

<xsl:template name="GetLastSegment">
<xsl:param name="value" />
<xsl:param name="separator" select="'.'" />
<xsl:variable name="allowed-characters">ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.</xsl:variable>
<xsl:choose>
  <xsl:when test="contains($value, $allowed-characters)">
    <xsl:call-template name="GetLastSegment">
      <xsl:with-param name="value" select="substring-after($value, $separator)" />
      <xsl:with-param name="separator" select="$separator" />
    </xsl:call-template>
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="$value" />
  </xsl:otherwise>
</xsl:choose>
</xsl:template>

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xslt