我需要獲取每個'/'的值,但由於文件中包含特殊字符,我無法獲得正確的輸出。我如何使用正確的正則表達式來檢查?我正在使用<xsl:analyze-string>
元素來獲取值。這裏是我的示例文件:如何使用正確的正則表達式
INPUTFILE:
<Communication>
<DialNumber>Phone/+31-3424-27385/null/Phone/+06-32-7890-565/Mobile(Office)/null/+313-(424)-28500/Fax</DialNumber>
</Communication>
預期輸出
<Communication>
<ChannelCode>Phone</ChannelCode>
<UseCode>null</UseCode>
<DialNumber>+31-3424-27385</DialNumber>
</Communication>
<Communication>
<ChannelCode>Phone</ChannelCode>
<UseCode>Mobile(Office)</UseCode>
<DialNumber>+06-32-7890-565</DialNumber>
</Communication>
<Communication>
<ChannelCode>null</ChannelCode>
<UseCode>Fax</UseCode>
<DialNumber>+313-(424)-28500</DialNumber>
</Communication>
XSLTCode
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="DialNumber">
<xsl:analyze-string select="normalize-space()" regex="(\w+)/(\w+)/(\w+)">
<xsl:matching-substring>
<Communication>
<ChannelCode>
<xsl:value-of select="regex-group(1)"/>
</ChannelCode>
<UseCode>
<xsl:value-of select="regex-group(3)"/>
</UseCode>
<DialNumber>
<xsl:value-of select="regex-group(2)"/>
</DialNumber>
</Communication>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
我需要檢查'/'後面的第3個單詞以及後面的3個單詞,最後3個單詞。它看起來像這樣:
Phone/+31-3424-27385/null
Phone/+06-32-7890-565/Mobile(Office)
null/+313-(424)-28500/Fax
首屆正則表達式,我需要在<Channel>
分配,在<DialNumber>
第二和第三的<UseCode>
。
非常感謝您的反饋。
感謝您的反饋。 – user7918368