내가 패턴을 찾아 일치하는 특정 패턴 주위에 "묶어야 할 필요가있는 xml 파일이 파일에 이제XSLT의 XSL :. 분석 문자열 및 정규식 표현
<xml>
<foo>
<id>1</id>
<description>This is section 1, this is section 1 or 2, this is section 1 and 2</description>
</foo>
</xml>
나는 찾을 수있다 패턴 "섹션 1", "섹션 1 또는 2"및 "섹션 1 및 2"를 입력하고 일치하는 단어 주위에 "표시를하십시오.
나는이 같은 인 XSLT를 작성했습니다 :
<xsl:template match="text()">
<xsl:analyze-string select="." regex="section\s\d+|section\s\d+\s+or\s+\d|section\s\d+\s+and\s+\d">
<xsl:matching-substring>
<xsl:if test="matches(.,'section\s\d+')" >
<xsl:text>"</xsl:text>
<xsl:value-of select="."/>
<xsl:text>"</xsl:text>
</xsl:if>
<xsl:if test="matches(.,'section\s\d+\s+or\s+\d')" >
<xsl:text>"</xsl:text>
<xsl:value-of select="."/>
<xsl:text>"</xsl:text>
</xsl:if>
<xsl:if test="matches(.,'section\s\d+\s+and\s+\d')" >
<xsl:text>"</xsl:text>
<xsl:value-of select="."/>
<xsl:text>"</xsl:text>
</xsl:if>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="current()"/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
내가 여기에 직면하고 문제는 내가 욕망 결과
을 받고 있지 않다 그래서 패턴 "섹션 1"뿐만 아니라 다른 모든 패턴과 일치하는 것입니다상기 변환 결과는 난이 출력을 원하는
<xml>
<foo>
<id>1</id>
<description>This is "section 1", this is "section 1" or 2, this is "section 1" and 2</description>
</foo>
</xml>
이다.
<xml>
<foo>
<id>1</id>
<description>This is "section 1", this is "section 1 or 2", this is "section 1 and 2"</description>
</foo>
</xml>
아이디어를 구현하는 방법 ... 원하는 결과를 얻으십시오.
감사합니다.
이 귀하의 의견에 작업 표시
David 덕분에 완벽하게 작동했습니다. "섹션 1 또는 2"로 제한되어 있기 때문에 "섹션 1 또는 2 또는 3"을 선택해야한다는 등의 일반화가 가능하다는 것을 알고 싶었습니다. – atif
예, 변경 하시겠습니까? a *와 어쩌면 (또는 |)으로 바꾸거나 (또는 |), 1, 2 또는 3이 잘 작동해야합니다. –