XPath - 从字符串中提取数值 [英] XPath - extract numeric value out of string

查看:74
本文介绍了XPath - 从字符串中提取数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<Description>this is my value 822880494 this is my value</Description>

我对 xpath、xml 和 stylevision 很陌生,所以这可能是一个基本问题.

I'm quite new to xpath, xml and stylevision so this might be a basic problem.

我正在使用 stylevision 2010 和 xpath 为架构创建 sps/xslt.

I am using stylevision 2010 and xpath to create an sps/xslt for an schema.

在上面的节点中,您可以看到节点内有一个数值,我想提取该值并将其转换为我的 pdf/html 中的链接.问题是我似乎无法提取它.子字符串不是一个选项,因为值的长度和其中的数值的位置是不同的.

In the above node you can see there is a numeric value inside the node and I want to extract that value and turn it into a link in my pdf/html. The problem is that i cant seem to extract it. Substring is not an option since the length of the value and the position of the numeric value inside it varies.

有些人可能会认为架构的组成很糟糕,数值应该在一个单独的节点/属性/...我无能为力,因为这个架构是由另一家公司提供的.

Some will probably think that the schema is badly composed and that the numeric value should be in a seperate node/attribute/... There is nothing I can do about that since this schema is provided by another company.

提前致谢!

推荐答案

StyleVision 2010 似乎支持 XSLT 2.0,因此您可以使用 2.0 样式表并执行类似的操作

StyleVision 2010 seems to support XSLT 2.0, so you could use a 2.0 stylesheet and do something like

<xsl:analyze-string select='$foo' regex='\d+'>
  <xsl:matching-substring>
    <number><xsl:value-of select='.' /></number>
  </xsl:matching-substring>
</xsl:analyze-string>

或者你想用这个号码做什么;带有数字的字符串是 元素内的上下文元素.

Or whatever you want to do with the number; the string with the number is the context element inside the <xsl:matching-substring> element.

Newtover 的 translate 想法(对于 XSLT 1.0)看起来像这样:

Newtover's translate idea (for XSLT 1.0) would look like this:

<xsl:value-of select="translate(., translate(., '0123456789', ''), '')" />

但如果您的输入包含多个数字,则只会将它们连接起来.

But if your input contains multiple numbers, that will simply concatenate them.

这篇关于XPath - 从字符串中提取数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆