【发布时间】:2011-05-06 16:39:55
【问题描述】:
我正在学习 XSLT,目前我真的陷入困境并且找不到解决方案。如果您能帮我解决这个问题,我将不胜感激。 下面你可以找到一个例子
$string 的值:
<img src="Afbeeldingen_Hotpot/beer.jpg" alt="afbeelding van een beer" title="beer" width="170" height="144" style="display:block; margin-left:auto; margin-right:auto; text-align:center;" style="float:center;" />
我的目标是过滤掉图像的高度......在这个例子中是“144”。 我从这个网站得到的functx:index-of-string:http://www.xsltfunctions.com/xsl/functx_index-of-string.html
这是我现在使用的 XSLT 代码:
<xsl:variable name="positionHeight" as="xs:integer"><xsl:value-of select="functx:index-of-string($string,'height=') + 8"/></xsl:variable>
<xsl:variable name="partStringHeight" as="xs:string"><xsl:value-of select="substring($string,$positionHeight)"/></xsl:variable>
<xsl:variable name="lengthHeight" as="xs:integer"><xsl:value-of select="functx:index-of-string($partStringHeight,'style=' - 3)"/></xsl:variable>
<xsl:variable name="height" as="xs:string"><xsl:sequence select="substring($partStringHeight,1,$lengthHeight)"/></xsl:variable>
在我想使用的 XSLT 代码下面,但由于“”的字符串索引为零”而出现错误。
<xsl:variable name="positionHeight" as="xs:integer"><xsl:value-of select="functx:index-of-string($string,'height=') + 8"/></xsl:variable>
<xsl:variable name="partStringHeight" as="xs:string"><xsl:value-of select="substring($string,$positionHeight)"/></xsl:variable>
<xsl:variable name="lengthHeight" as="xs:integer"><xsl:value-of select="functx:index-of-string($partStringHeight,'"' - 1)"/></xsl:variable>
<xsl:variable name="height" as="xs:string"><xsl:sequence select="substring($partStringHeight,1,$lengthHeight)"/></xsl:variable>
有没有办法获取子字符串的索引,例如:
" and &#x003E;
因为我有很多字符串,所以我需要高度,但没有出现“style=”..
【问题讨论】: