我有一个简单的 xml 文本和一个小人物。我想找到文中提到的所有“人”,并使用人物画像中的信息对其进行标记。我的文字如下所示:
<text>
<div>
<p>Mohandas Ghandi was an Indian lawyer, born in 1869.</p>
<p>Albert Einstein was a German physicist, born in 1879.</p>
<p>Helen Keller was an American author, born in 1880.</p>
<p>Joan Baez is an American singer/songwriter, born in 1941.</p>
</div>
</text>
我的人像是这样的:
<people>
<person id="ghandi">
<name>Mohandas Ghandi</name>
<birthPlace>Porbandar, India</birthPlace>
</person>
<person id="einstein">
<name>Albert Einstein</name>
<birthPlace>Ulm, Germany</birthPlace>
</person>
<person id="keller">
<name>Helen Keller</name>
<birthPlace>Tuscumbia, USA</birthPlace>
</person>
</people>
到目前为止,我有这个 xslt (2.0):
<xsl:variable name="personography" select="doc('people.xml')"/>
<xsl:variable name="pName" select="$personography//person[1]/name"/>
<xsl:variable name="pId" select="$personography//person[1]/@id"/>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template name="encNames" match="text()">
<xsl:analyze-string select="." regex="{$pName}">
<xsl:matching-substring>
<persName corresp="{concat('people.xml#',$pId)}">
<xsl:value-of select="."/>
</persName>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:copy-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
我得到了这个:
<text>
<div>
<p><persName corresp="people.xml#ghandi">Mohandas Ghandi</persName> was an Indian lawyer, born in 1869.</p>
<p>Albert Einstein was a German physicist, born in 1879.</p>
<p>Helen Keller was an American author, born in 1880.</p>
<p>Joan Baez is an American singer/songwriter, born in 1941.</p>
</div>
</text>
所以,我的问题是,我如何标记文本中的其他人?我认为它需要一个使用跟随兄弟的函数,但我没有比这更进一步。我错过了什么?我至少在正确的轨道上吗?谢谢。