Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml xslt命名模板编号始终进入xsl:otherwise块_Xml_Xslt_Xpath - Fatal编程技术网

Xml xslt命名模板编号始终进入xsl:otherwise块

Xml xslt命名模板编号始终进入xsl:otherwise块,xml,xslt,xpath,Xml,Xslt,Xpath,我有一个日期后缀函数,它将st、nd、rd、th后缀与日期相加 <xsl:template name="date_suffix"> <xsl:param name="date" /> <xsl:choose> <xsl:when test="$date &gt; 10 and $date &lt; 14">th</xsl:when> <xsl:when test="(

我有一个日期后缀函数,它将st、nd、rd、th后缀与日期相加

<xsl:template name="date_suffix">
    <xsl:param name="date" />
    <xsl:choose>
        <xsl:when test="$date &gt; 10 and $date &lt; 14">th</xsl:when>
        <xsl:when test="($date mod 10) = 1">st</xsl:when>
        <xsl:when test="($date mod 10) = 2">nd</xsl:when>
        <xsl:when test="($date mod 10) = 3">rd</xsl:when>
        <xsl:otherwise>th</xsl:otherwise>
    </xsl:choose>
</xsl:template>

th
圣
钕
研发部
th
我这样称呼它

<xsl:template match="date">
    <xsl:value-of select="." />
    <xsl:call-template name="date_suffix">
        <xsl:with-param name="date" seelect="." />
    </xsl:call-template>
</xsl:template>

这是我的XAML片段

    <dob>
        <date>23</date>
        <month>Dec</month>
        <year>1987</year>
    </dob>

23
12月
1987

问题是我看到的是
23次
,而我预期的是
23次
。这个
选择
当我直接在
块中使用时,它可以正常工作,但当被称为命名模板时,它不能正常工作

尝试将
seelect
更改为
选择

如果您不受XSL版本1.0的限制,使用具有强类型参数的函数而不是命名模板可能会有所帮助:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xyz="urn:mystuff"
version="2.0">
    <xsl:output encoding="utf-8" indent="yes" method="xml" />

    <xsl:template match="date">
        <xsl:value-of select="." />
        <xsl:value-of select="xyz:date_suffix(.)" />
    </xsl:template>

    <xsl:function name="xyz:date_suffix" as="xs:string">
        <xsl:param name="date" as="xs:integer"/>
        <xsl:choose>
            <xsl:when test="($date mod 10) = 1">st</xsl:when>
            <xsl:when test="($date mod 10) = 2">nd</xsl:when>
            <xsl:when test="($date mod 10) = 3">rd</xsl:when>
            <xsl:otherwise>th</xsl:otherwise>
        </xsl:choose>
    </xsl:function>

</xsl:stylesheet>

圣
钕
研发部
th

对于诊断,使用xsl:message显示$date的值。