有没有办法在一组字符后从字符串中提取数字。
我们的软件使用XSLT文件将电子邮件转换为XML文件。在电子邮件的主题行中,可以引用已打开的事件/服务请求/任务。
例如 - 电子邮件的主题可以是:
RE: SR#51417: D_SATTER-NOV60LKA-I_G-A0201244I 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文件时出错
答案 0 :(得分:1)
这是一个解决方案:)
<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>
&#13;