gpt4 book ai didi

linux - 如何处理 ".xsl"文件中的字符串序列或数组?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:40:22 26 4
gpt4 key购买 nike

我在 xsl STLesheet 中有字符串序列/数组。

例如变量列表当我如下打印上述变量的值时

<xsl:value-of select="$varList"/>

打印如下

varList="hw.co.gdh gd.kj.xhd bh.ko.sag hf.sj.kjh"

现在我必须从上面的变量中分别获取每个字符串。

即“hw.co.gdh”,“gd.kj.xhd”分开。

我该怎么做?有没有申请<xsl:for-each>的选项循环还是别的什么?

我正在使用 xsl 的 version="1.0"。

最佳答案

我将向您演示如何根据提供的递归函数在 XSLT 1.0 中拆分字符串 here .

输入

<root>
<varlist>a.a.a b.b.b c.c.c</varlist>
</root>

XSL

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

<xsl:template match="/root">
<xsl:variable name="varList" select="varlist" />
<xsl:variable name="nodelist">
<xsl:call-template name="output-tokens">
<xsl:with-param name="list"><xsl:value-of select="$varList"/></xsl:with-param>
</xsl:call-template>
</xsl:variable>
<nodelist>
<xsl:copy-of select="$nodelist"/>
</nodelist>
</xsl:template>

<xsl:template name="output-tokens">
<xsl:param name="list" />
<xsl:variable name="newlist" select="concat(normalize-space($list), ' ')" />
<xsl:variable name="first" select="substring-before($newlist, ' ')" />
<xsl:variable name="remaining" select="substring-after($newlist, ' ')" />
<id>
<xsl:value-of select="$first" />
</id>
<xsl:if test="$remaining">
<xsl:call-template name="output-tokens">
<xsl:with-param name="list" select="$remaining" />
</xsl:call-template>
</xsl:if>
</xsl:template>

输出

<nodelist>
<id>a.a.a</id>
<id>b.b.b</id>
<id>c.c.c</id>
</nodelist>

注意除了调用模板output-tokens,我什么也没做。

关于linux - 如何处理 ".xsl"文件中的字符串序列或数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5947183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com