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_Xslt 2.0 - Fatal编程技术网

在XSLT中,我可以不标记任何内容吗?

在XSLT中,我可以不标记任何内容吗?,xslt,xslt-2.0,Xslt,Xslt 2.0,我需要将字符串'abcdef'转换为其部分'a','b','c','d','e','f'。我做了愚蠢的尝试 标记化('abcdef','') 当然,这会返回一个FORX0003错误(tokenize()中的正则表达式不能与零长度字符串匹配) 实际上,我正在尝试将字符串最终转换为'a/b/c/d/e/f',因此,任何直接将我转换到该状态的快捷方式都将非常有用 (我正在使用用于.NET平台的Saxon 9.3)要从字符串中获取所需的字符序列,$str请使用这对函数和: for $c in strin

我需要将字符串'abcdef'转换为其部分'a','b','c','d','e','f'。我做了愚蠢的尝试 标记化('abcdef','') 当然,这会返回一个FORX0003错误(tokenize()中的正则表达式不能与零长度字符串匹配)

实际上,我正在尝试将字符串最终转换为'a/b/c/d/e/f',因此,任何直接将我转换到该状态的快捷方式都将非常有用


(我正在使用用于.NET平台的Saxon 9.3)

要从字符串中获取所需的字符序列,
$str
请使用这对函数和

for $c in string-to-codepoints($str)
 return
    codepoints-to-string($c)
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>

 <xsl:template match="/">
     <xsl:sequence select=
      "string-join(
              for $c in string-to-codepoints('ABC')
              return
                 codepoints-to-string($c),
            '/'
                     )
      "/>
 </xsl:template>
</xsl:stylesheet>
A/B/C
65 66 67

codepoints-to-string($code-seq)
要获得以“/”作为连接字符串连接的字符序列,只需对上述表达式应用

以下是完整的代码示例

for $c in string-to-codepoints($str)
 return
    codepoints-to-string($c)
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>

 <xsl:template match="/">
     <xsl:sequence select=
      "string-join(
              for $c in string-to-codepoints('ABC')
              return
                 codepoints-to-string($c),
            '/'
                     )
      "/>
 </xsl:template>
</xsl:stylesheet>
A/B/C
65 66 67

codepoints-to-string($code-seq)
说明

for $c in string-to-codepoints($str)
 return
    codepoints-to-string($c)
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>

 <xsl:template match="/">
     <xsl:sequence select=
      "string-join(
              for $c in string-to-codepoints('ABC')
              return
                 codepoints-to-string($c),
            '/'
                     )
      "/>
 </xsl:template>
</xsl:stylesheet>
A/B/C
65 66 67

codepoints-to-string($code-seq)
string-to-codepoints($str)
生成一系列表示字符串中每个字符的代码点(可以将它们视为“字符代码”)

例如

string-to-codepoints('ABC')
生成序列

for $c in string-to-codepoints($str)
 return
    codepoints-to-string($c)
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>

 <xsl:template match="/">
     <xsl:sequence select=
      "string-join(
              for $c in string-to-codepoints('ABC')
              return
                 codepoints-to-string($c),
            '/'
                     )
      "/>
 </xsl:template>
</xsl:stylesheet>
A/B/C
65 66 67

codepoints-to-string($code-seq)
字符串到-codepoints()
的反函数。给定一个码点序列,它生成字符串,其字符由序列中的码点表示。因此:

codepoints-to-string((65,66,67))
生成字符串:

ABC
因此:

for $c in string-to-codepoints($str)
 return
    codepoints-to-string($c)
获取
$str
中每个字符的代码点,并将其转换为单独的字符串

使用
string-join()
我们然后使用提供的连接字符“/”连接所有这些单独的字符串。

使用此行:

replace(replace($input, "(.)", "$1/", "s"), "(.*).$", "$1", "s")
其中,
$input
指向原始字符串。此行的返回值是您所需的字符串

a/b/c/d/e/f

这个解决方案非常有效,但我接受了FailedDev的答案,因为它较短,而且(像我这样的)简单的人更容易理解