我已经通过了几个例子,并试图修改我的搜索,以了解什么是什么。
输入:
<Description>Ottelu pelattu 22.4.2018. Gagarin Cupin 5. finaaliottelu. Selostus: Antti Mäkinen.</Description>
<Description>Ottelu pelattu 20.4.2018. Gagarin Cupin 1. finaaliottelu. Selostus: Antti Mäkinen.</Description>
<Description>Ottelu pelattu 22.4.2018. Gagarin Cupin 2. puolivälierä. Selostus: Antti Mäkinen.</Description>`我想要做的是选择这些输出:
中间没有小点。
我可以使用子字符串-前/后,但我知道它可能是有用的使用regex?
我做了这个,得到了我需要的东西:Gagarin Cupin\s\d\W\s\w*[a-zA-ZäöüÄÖÜß]*
但是现在我如何在XSLT中使用它呢?我应该使用的是analyze-string()吗?或者matches()在某种程度上?
XSLT:
<xsl:variable name="episode" select="Description"/>
<xsl:variable name="fetchcup">
<xsl:analyze-string select="$episode" regex="Gagarin Cupin\s\d\W\s\w*[a-zA-ZäöüÄÖÜß]*">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<Cup><xsl:value-of select="$fetchcup"/></Cup>但老实说,我觉得我错过了一些基本的工作原理,尽管我看了教程的网页和例子。如果我有一只脚在门上,我可以进一步应用它。
发布于 2018-08-23 16:56:48
正则表达式在单个Description元素的上下文中工作,如果要输出匹配的字符串,只需对上下文项或regex-group(0)使用. (参见https://www.w3.org/TR/xslt-30/#func-regex-group)。在您的情况下,使用regex-group(1)没有意义,因为正则表达式没有任何子表达式。
<xsl:template match="Description">
<cup>
<xsl:analyze-string select="." regex="Gagarin Cupin\s\d\W\s\w*[a-zA-ZäöüÄÖÜß]*">
<xsl:matching-substring>
<xsl:value-of select="."/>
</xsl:matching-substring>
</xsl:analyze-string>
</cup>
</xsl:template>https://xsltfiddle.liberty-development.net/nc4NzQH中的模板输出
<cup>Gagarin Cupin 5. finaaliottelu</cup>
<cup>Gagarin Cupin 1. finaaliottelu</cup>
<cup>Gagarin Cupin 2. puolivälierä</cup>对于您的三个Description元素,我希望我正确地理解为期望的输出。
https://stackoverflow.com/questions/51989441
复制相似问题