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
XSLT:用逗号反转字符串_Xslt - Fatal编程技术网

XSLT:用逗号反转字符串

XSLT:用逗号反转字符串,xslt,Xslt,我有一个XML文件: <schools> <schcool> school1, school2, school3, school4, school5 </schcool> </schools> 学校一,学校二,学校三,学校四,学校五 我想编写XSLT(1.0版),将结果更改为如下相反顺序: <schools> <schcool> school

我有一个XML文件:

<schools>
    <schcool>
        school1, school2, school3, school4, school5
        </schcool>
    </schools>

学校一,学校二,学校三,学校四,学校五
我想编写XSLT(1.0版),将结果更改为如下相反顺序:

   <schools>
    <schcool>
        school5, school4, school3, school2, school1
        </schcool>
    </schools>
  <call-template name="split">
    <with-param name="s" select="." />
  </call-template>

学校5,学校4,学校3,学校2,学校1
有人能帮我吗?非常感谢


DY

没有xsl的变体:选择:

  <xsl:template name="reverse">
    <xsl:param name="text"/>
    <xsl:param name="comma" select="false()"/>
    <xsl:variable name="item" select="substring-before(concat($text, ','), ',')"/>    
    <xsl:if test="normalize-space($item) != ''">
      <xsl:call-template name="reverse">
        <xsl:with-param name="text" select="substring-after(concat($text, ','), concat($item, ','))"/>
        <xsl:with-param name="comma" select="true()"/>
      </xsl:call-template>
    </xsl:if>
    <xsl:value-of select="$item"/>
    <xsl:if test="$comma and $item != ''">
      <xsl:text>,</xsl:text>
    </xsl:if>
  </xsl:template>

,

没有xsl的变体:选择:

  <xsl:template name="reverse">
    <xsl:param name="text"/>
    <xsl:param name="comma" select="false()"/>
    <xsl:variable name="item" select="substring-before(concat($text, ','), ',')"/>    
    <xsl:if test="normalize-space($item) != ''">
      <xsl:call-template name="reverse">
        <xsl:with-param name="text" select="substring-after(concat($text, ','), concat($item, ','))"/>
        <xsl:with-param name="comma" select="true()"/>
      </xsl:call-template>
    </xsl:if>
    <xsl:value-of select="$item"/>
    <xsl:if test="$comma and $item != ''">
      <xsl:text>,</xsl:text>
    </xsl:if>
  </xsl:template>

,

谢谢。你节省了我的时间

我通过以下方式删除空间:

<xsl:call-template name="split">
     <xsl:with-param name="s" select="normalize-space(.)" />
</xsl:call-template>

非常感谢


谢谢你。你节省了我的时间

我通过以下方式删除空间:

<xsl:call-template name="split">
     <xsl:with-param name="s" select="normalize-space(.)" />
</xsl:call-template>

非常感谢


DY

编辑后,两个XML片段看起来相同。这是故意的吗?呵呵,刚换回来。谢谢。@DotNet用户,还没有接受任何答案吗?只是提醒一下。编辑后,两个XML片段看起来都一样。这是故意的吗?呵呵,刚换回来。谢谢。@DotNet用户,还没有接受任何答案吗?只是提醒一下,德纳达。实际上,在XSLT中对模板的递归调用非常频繁。你应该习惯这种技巧。注意,如果文本中没有逗号,你的函数将不会返回任何结果……嗯。为什么?据我所知,没有逗号的情况由otherwise条款处理。它甚至不应该画出多余的尾随逗号。旧版本中有一个BUG,我前几分钟刚刚纠正了它……我讨厌value=“”和select=“”属性。我总是把它们混在一起。实际上,在XSLT中对模板的递归调用非常频繁。你应该习惯这种技巧。注意,如果文本中没有逗号,你的函数将不会返回任何结果……嗯。为什么?据我所知,没有逗号的情况由otherwise条款处理。它甚至不应该画出多余的尾随逗号。旧版本中有一个BUG,我前几分钟刚刚纠正了它……我讨厌value=“”和select=“”属性。我总是把它们混在一起。嗨,厄洛克,也谢谢你。嗨,厄洛克,也谢谢你。