我的字符串为o,t,a,f,m,i,i,s,r,a(对冲),v,pft,pft,pft,pft,pft,pft,pft,pft,try trima separted tokenize separted tokenize结果是a f m i s a a a thed v pft,并重复了一个不正确的结果。
我在XSL下尝试了:XML节点将具有O,T,A,F,M,I,S,R,A(对冲),V,PFT,PFT
XML:
<?xml version="1.0" encoding="UTF-8"?>
<path>
<some>O, T, A, F, M, I, S, R, A (Hedged), V, PFT</some>
</path>
<xsl:variable name="val" select="//path/some" />
<xsl:for-each select="str:tokenize($val, ', ')">
<xsl:variable name="tokVal" select="."/>
<h2><xsl:value-of select="$tokVal"/></h2>
</xsl:for-each>
预期的输出是A F M I S R A(对冲)V Pft
使用XSLT 2.0,您最终发布的XML输入我无法在http://xsltransform.net/bezjrkj上重现问题,输入为
<path>
<some>O, T, A, F, M, I, S, R, A (Hedged), V, PFT</some>
</path>
最小xslt是
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<html>
<head>
<title>Test</title>
</head>
<xsl:apply-templates/>
</html>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="some">
<xsl:for-each select="tokenize(., 's*,s*')">
<h2>
<xsl:value-of select="."/>
</h2>
</xsl:for-each>
</xsl:template>
</xsl:transform>
输出是
<!DOCTYPE html
PUBLIC "XSLT-compat">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
</head>
<path>
<h2>O</h2>
<h2>T</h2>
<h2>A</h2>
<h2>F</h2>
<h2>M</h2>
<h2>I</h2>
<h2>S</h2>
<h2>R</h2>
<h2>A (Hedged)</h2>
<h2>V</h2>
<h2>PFT</h2>
</path>
</html>
渲染为
o
t
a
f
m
i
s
r
a(对冲)
v
pft