[英]Extracting a number from a string in a XSLT file
有沒有一種方法可以從一組字符后的字符串中提取數字。
我們的軟件使用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文件時出錯
這里是一個解決方案:)
<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.