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: <p> <image width="10cm"/> <image width="3cm"/> </p> 我需要计算这些图像的总宽度。 当我只有一张图片时,这很简单: <template match="p"> <xsl:variable name="imgwidth"> <xsl:value-of select="number(su

我有一个包含一系列图像及其宽度的XML:

<p>
    <image width="10cm"/>
    <image width="3cm"/>
</p>

我需要计算这些图像的总宽度。 当我只有一张图片时,这很简单:

<template match="p">
    <xsl:variable name="imgwidth">
        <xsl:value-of select="number(substring-before(image/@width,'cm'))"/>

天真地,我尝试扩展它以容纳更多图像:

<xsl:value-of select="sum(number(substring-before(image/@width,'cm')))"/>

当我在样本上运行此操作时,会收到一条错误消息:

fn:substring-before()的第一个参数不允许有多个项目的序列(“10cm”、“3cm”)


我已经做了一些搜索,但不知道如何在XSLT 2.0中的
中的每个图像节点上运行子字符串,您可以编写以下内容

<xsl:value-of select="sum(image/number(substring-before(@width,'cm')))"/>

或者,也许这

<xsl:value-of select="sum(for $i in image return number(substring-before($i/@width, 'cm')))"/>


您能使用XSLT 2.0或3.0吗?是的,样式表已经在使用XSLT 2了。这么简单,是吗?我一直在寻找各种各样的切线,看fn:sequence,等等。