XSLT匹配记录长度<;8.

XSLT匹配记录长度<;8.,xslt,Xslt,我已经创建了以下XSLT,它将确保发送的字段只填充数字,但是我不确定如何调整它以包括一个额外的语句,以确保其长度不超过8个字符 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"

我已经创建了以下XSLT,它将确保发送的字段只填充数字,但是我不确定如何调整它以包括一个额外的语句,以确保其长度不超过8个字符

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="record[translate(employeeNumber, '0123456789', '')]"/>
</xsl:stylesheet>

您是说希望忽略员工编号大于8个字符的记录吗?如果是这样的话,您可以像这样添加另一个匹配的模板来忽略它们

<xsl:template match="record[string-length(employeeNumber) > 8]"/>

这是一个模板,可以用来截断字符串。。。希望这能起作用

<xsl:template name="fullortruncate">
    <xsl:param name="input" />
    <xsl:choose>
        <xsl:when test="string-length($input)>8">
            <xsl:value-of select="substring($input, 0, 8)"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$input"/>
        </xsl:otherwise>
    </xsl:choose> 
</xsl:template>

您可以使用调用模板调用模板

<xsl:call-template name="fullortruncate">
<xsl:with-param name="input" select="[your input]"/>
</xsl:call-template>

非常感谢,我不知道我可以将多模块匹配放在一起,所以首先检查长度,然后检查内容。非常感谢你。