使用 XSLT 2.0 按照模式拆分字符串
Split string following a pattern using XSLT 2.0
我有一个字符串需要使用 XSLT 2.0 进行解析
输入字符串
Hoffmann, Rüdiger (Universtiy-A, SomeCity, (SomeCountry); University-B, SomeCity, (SomeCountry)); Author, X; Author, B. (University-C, SomeCity (SomeCountry))
预期输出
Hoffmann, Rüdiger (Universtiy-A, SomeCity, (SomeCountry); University-B, SomeCity, (SomeCountry))
Author, X
Author, B. (University-C, SomeCity (SomeCountry))
结构是-作者姓名,后面是他的大学。但是,一位作者可以拥有两所大学。大学之间和两组作者之间的分隔符是同一个。 (在这种情况下是分号)。
我需要根据作者所属组的分隔符来拆分它,忽略隶属关系之间的分号。
我相信可以借助正则表达式来完成,但我自己构建正则表达式的经验不多。
只要大学列表和全国各地的括号始终存在,您就可以匹配它们:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="xs mf">
<xsl:output method="text"/>
<xsl:param name="authors">Author, A. (Universtiy-A, SomeCity, (SomeCountry); University-B, SomeCity, (SomeCountry));Author, B. (University-C, SomeCity (SomeCountry))</xsl:param>
<xsl:template match="/">
<xsl:value-of select="mf:split($authors)" separator=" "/>
</xsl:template>
<xsl:function name="mf:split" as="xs:string*">
<xsl:param name="input" as="xs:string"/>
<xsl:analyze-string select="$input" regex="[^;)]*?\([^(]*?\([^(]*?\)\)">
<xsl:matching-substring>
<xsl:sequence select="."/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:function>
</xsl:transform>
我有一个字符串需要使用 XSLT 2.0 进行解析
输入字符串
Hoffmann, Rüdiger (Universtiy-A, SomeCity, (SomeCountry); University-B, SomeCity, (SomeCountry)); Author, X; Author, B. (University-C, SomeCity (SomeCountry))
预期输出
Hoffmann, Rüdiger (Universtiy-A, SomeCity, (SomeCountry); University-B, SomeCity, (SomeCountry))
Author, X
Author, B. (University-C, SomeCity (SomeCountry))
结构是-作者姓名,后面是他的大学。但是,一位作者可以拥有两所大学。大学之间和两组作者之间的分隔符是同一个。 (在这种情况下是分号)。
我需要根据作者所属组的分隔符来拆分它,忽略隶属关系之间的分号。
我相信可以借助正则表达式来完成,但我自己构建正则表达式的经验不多。
只要大学列表和全国各地的括号始终存在,您就可以匹配它们:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="xs mf">
<xsl:output method="text"/>
<xsl:param name="authors">Author, A. (Universtiy-A, SomeCity, (SomeCountry); University-B, SomeCity, (SomeCountry));Author, B. (University-C, SomeCity (SomeCountry))</xsl:param>
<xsl:template match="/">
<xsl:value-of select="mf:split($authors)" separator=" "/>
</xsl:template>
<xsl:function name="mf:split" as="xs:string*">
<xsl:param name="input" as="xs:string"/>
<xsl:analyze-string select="$input" regex="[^;)]*?\([^(]*?\([^(]*?\)\)">
<xsl:matching-substring>
<xsl:sequence select="."/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:function>
</xsl:transform>