Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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/4/string/5.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 1.0中每2个空格拆分一个字符串_Xml_String_Xslt_Split - Fatal编程技术网

Xml XSLT 1.0中每2个空格拆分一个字符串

Xml XSLT 1.0中每2个空格拆分一个字符串,xml,string,xslt,split,Xml,String,Xslt,Split,在XSLT1.0中,我需要关于在每秒钟的空格上拆分字符串的帮助 我是XSLT新手 我有字符串: <gml:posList>50.5625 4.54111 50.56333 4.55167 50.56278 4.57694 50.55972 4.60167 50.55361 4.625 50.54528</gml:posList> 50.5625 4.54111 50.56333 4.55167 50.56278 4.57694 50.55972 4.60167 50.5

在XSLT1.0中,我需要关于在每秒钟的空格上拆分字符串的帮助 我是XSLT新手 我有字符串:

<gml:posList>50.5625 4.54111 50.56333 4.55167 50.56278 4.57694 50.55972 4.60167 50.55361 4.625 50.54528</gml:posList>
50.5625 4.54111 50.56333 4.55167 50.56278 4.57694 50.55972 4.60167 50.55361 4.625 50.54528
我需要在每一秒的空间分割字符串。。。 我想要输出:

50.5625 4.54111

50.56333 4.55167


感谢您的帮助

使用命名递归模板:

<xsl:template name="tokenize">
    <xsl:param name="text"/>
    <xsl:param name="delimiter" select="' '"/>
    <xsl:choose>
        <xsl:when test="contains($text, $delimiter) and contains(substring-after($text, $delimiter), $delimiter)">
            <token>
                <xsl:value-of select="substring-before($text, $delimiter)"/>
                <xsl:value-of select="$delimiter"/>
                <xsl:value-of select="substring-before(substring-after($text, $delimiter), $delimiter)"/>
            </token>
            <!-- recursive call -->
            <xsl:call-template name="tokenize">
                <xsl:with-param name="text" select="substring-after(substring-after($text, $delimiter), $delimiter)"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <token>
                <xsl:value-of select="$text"/>
            </token>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>


演示:

一个解决方案是两次在之前应用
子字符串,在
之后应用
子字符串,并在其余部分重复调用该模板

<xsl:template name="splitEverySecond">
  <xsl:param name="pText" select="."/>
  <xsl:if test="string-length($pText)">
    <xsl:value-of select="concat(substring-before($pText,' '),' ',substring-before(substring-after($pText,' '),' '),'&#xa;')" />
    <xsl:call-template name="splitEverySecond">
      <xsl:with-param name="pText" select="substring-after(substring-after($pText,' '),' ')" />
    </xsl:call-template>
  </xsl:if>
</xsl:template>

<xsl:template match="posList">
  <xsl:call-template name="splitEverySecond" select="normalize-space(.)" />
</xsl:template>

相当简短和简单

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>

  <xsl:template match="text()" name="split">
    <xsl:param name="pText" select="."/>

    <xsl:if test="normalize-space($pText)">
      <xsl:variable name="vText" select="concat(normalize-space($pText), ' ')"/>

      <xsl:value-of select="substring-before($vText, ' ')"/>
      <xsl:value-of select=
        "concat(' ', substring-before(substring-after($vText, ' '), ' '), '&#xA;')"/>

      <xsl:call-template name="split">
        <xsl:with-param name="pText" select=
          "substring-after(substring-after($vText, ' '), ' ')"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>
50.5625 4.54111
50.56333 4.55167
50.56278 4.57694
50.55972 4.60167
50.55361 4.625
50.54528 
50.5625 4.54111
50.56333 4.55167
50.56278 4.57694
50.55972 4.60167
50.55361 4.625
50.54528