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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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 在xsl 1.0中更改逻辑_Xml_Xslt_Xslt 1.0 - Fatal编程技术网

Xml 在xsl 1.0中更改逻辑

Xml 在xsl 1.0中更改逻辑,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,我有一个文本字符串——“Parkering mva fri 30 stk 01.04.14-30.06.14”,我想从字符串中分别获取日期 我所做的是: <xsl:variable name="Letters"> <xsl:text>ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</xsl:text> </xsl:variable> <xs

我有一个文本字符串——“Parkering mva fri 30 stk 01.04.14-30.06.14”,我想从字符串中分别获取日期

我所做的是:

    <xsl:variable name="Letters">              
 <xsl:text>ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</xsl:text>
    </xsl:variable>
<xsl:variable name="S_Date">
 <xsl:value-of select="translate(STRING_VALUE,$Letters,'')"/>
</xsl:variable>
 <xsl:value-of select="normalize-space(substring-before($S_Date,'-'))"/>

abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvxyz

这是作为“30 01.04.14”生成的输出,我不想要30。我应该如何删除它。

您可以尝试以下方法。这将提取与########模式匹配的第一个单词(空格分隔)

XSLT1.0

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:param name="STRING_VALUE">Parkering mva fri 30 stk 01.04.14 - 30.06.14</xsl:param>

<xsl:template match="/">
    <output>
        <xsl:call-template name="first-date">
            <xsl:with-param name="text" select="$STRING_VALUE"/>
        </xsl:call-template>
    </output>
</xsl:template>

<xsl:template name="first-date">
    <xsl:param name="text"/>
    <xsl:param name="word" select="substring-before(concat($text, ' '), ' ')"/>
    <xsl:choose>
        <xsl:when test="translate($word, '0123456789', '##########')='##.##.##'">
            <xsl:value-of select="$word"/>
        </xsl:when>
        <xsl:when test="contains($text, ' ')">  
            <xsl:call-template name="first-date">
                <xsl:with-param name="text" select="substring-after($text, ' ')"/>
            </xsl:call-template>
        </xsl:when>
    </xsl:choose>
 </xsl:template>

</xsl:stylesheet>

Parkering mva周五30 stk 01.04.14-30.06.14

这并不简单——除非(第一个)日期之前出现的数字有一个固定的模式;在这种情况下,您可以跳过它们并继续使用它们后面的第一个空格。是的,您是对的,因为我们没有字符串的常量模式,任何东西都可以在日期之前存在。我们可以添加任何其他逻辑来工作或与非常量模式匹配吗?