我不知道如何解决我的基本问题:
我有一个带有@POINTS
属性的<Polygon>
元素,它包含一个数字列表,例如:
<Polygon POINTS="337 363 330 221 443 221 472 203 497 225 512 373 494 370 475 392 417 373 385 381 348 421"/>
我想以以下方式执行XSL转换:
<zone type="Polygon" points="337,363 330,221 443,221 472,203 497,225 512,373 494,370 475,392 417,373 385,381 348,421"/>
我想根据一个模式放一个逗号,实际上是在两个数字之间。
我尝试了<xsl:for-each>
和concat((函数,但它不起作用。
提前感谢您的建议和您的时间
在XSLT2/3中,您可以使用
<xsl:template match="@POINTS">
<xsl:attribute name="points">
<xsl:value-of separator=" ">
<xsl:for-each-group select="tokenize(.)" group-adjacent="(position() - 1) idiv 2">
<xsl:sequence select="string-join(current-group(), ',')"/>
</xsl:for-each-group>
</xsl:value-of>
</xsl:attribute>
</xsl:template>
或者在Saxon 9.8 PE支持的XSLT3中:
<xsl:template match="@POINTS">
<xsl:attribute name="points"
select="let $tokens := tokenize(.)
return
for-each-pair(
$tokens[position() mod 2 = 1],
$tokens[position() mod 2 = 0],
function($a, $b) { $a || ',' || $b }
)"/>
</xsl:template>