繁体   English   中英

从XSLT文件中的字符串中提取数字

[英]Extracting a number from a string in a XSLT file

有没有一种方法可以从一组字符后的字符串中提取数字。

我们的软件使用XSLT文件将电子邮件转换为XML文件。 在电子邮件的主题行中,可以有对已打开的事件/服务请求/任务的引用。

例如,电子邮件的主题可以是:

RE: SR#51417: D_SATTER-NOV60LKA-I_G-A0201244

I want to extract the Service Request Number 51417 from the Subject. The number will always be after the String "SR#". "SR#" could be written as "sr#", "Sr#" or "sR#".

I was trying to use the RegEx functions in XSLT but can't get it to work.

Do you have any suggestions on how to do this?

Thanks in advance.

Update I am trying the solution provided by cyclexx. This is the Code that I have put in my XSLT File:

<xsl:when test="contains($subject, 'SR#')"> <xsl:element name="Field"> <xsl:attribute name="Name"> <xsl:text>a_eco_parentObjectType</xsl:text> </xsl:attribute> <xsl:value-of select="'ServiceReq'"></xsl:value-of> </xsl:element> <xsl:element name="Field"> <xsl:attribute name="Name"> <xsl:text>a_eco_parentObjectID</xsl:text> </xsl:attribute> <xsl:analyze-string select ="$subject" regex="\s*[Ss][Rr]#([0-9]+)\s*"> <xsl:matching-substring> <SR> <xsl:value-of select="regex-group(1)"></xsl:value-of> </SR> </xsl:matching-substring> </xsl:analyze-string> </xsl:element>

变量$ subject包含正在处理的电子邮件文件的主题行。 输出文件仅包含:

ServiceReq

并且我收到一条错误消息::加载分层对象XSLT文件时出错

这里是一个解决方案:)

 <emails> <email> <subject>RE: SR#51417: D_SATTER-NOV60LKA-I_G-A0201244</subject> </email> <email> <subject>RE: Sr#565465: D_SATTER-NOV60LKA-I_G-A0201244</subject> </email> </emails> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" /> <xsl:template match="subject"> <xsl:variable name="v" select="." /> <xsl:analyze-string select="$v" regex="\\s*[Ss][Rr]#([0-9]+)\\s*"> <xsl:matching-substring> <SR> <xsl:value-of select="regex-group(1)" /> </SR> </xsl:matching-substring> <xsl:non-matching-substring> <subject> <xsl:value-of select="$v"/> </subject> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:template> </xsl:stylesheet> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM