【发布时间】:2014-11-21 17:48:40
【问题描述】:
我需要更改某些节点的文本,类似于Update the text of an element with XSLT based on param。
这是我的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title />
</titleStmt>
<publicationStmt>
<p />
</publicationStmt>
<sourceDesc>
<p />
</sourceDesc>
</fileDesc>
<encodingDesc>
<appInfo>
<application ident="TEI_fromDOCX" version="2.15.0">
<label>DOCX to TEI</label>
</application>
</appInfo>
</encodingDesc>
<revisionDesc>
<change>
<date>$LastChangedDate: 2014-10-19$</date>
</change>
</revisionDesc>
</teiHeader>
<text>
<body xml:id="test">
<head>DICTIONARY</head>
<entry>
<form type="hyperlemma" xml:lang="cu">
<orth>абиѥ</orth>
</form>
<form type="lemma" xml:lang="cu">
<orth>абиѥ</orth>
</form>
<form type="variant" xml:lang="cu">
<orth>а̓бїе</orth>
<form type="hyperlemma" xml:lang="cu">
<orth>а̓бїе</orth>
</form>
</form>
</entry>
</body>
</text>
</TEI>
我现在想替换 <orth> 之间的文字
<form type="variant" xml:lang="cu">
<orth>а̓бїе</orth>
<form type="hyperlemma" xml:lang="cu">
<orth>а̓бїе</orth>
</form>
</form>
通过前一个节点中<orth>的内容
<entry>
<form type="hyperlemma" xml:lang="cu">
<orth>абиѥ</orth>
</form>
为了得到以下输出:
<entry>
<form type="hyperlemma" xml:lang="cu">
<orth>абиѥ</orth>
</form>
<form type="lemma" xml:lang="cu">
<orth>абиѥ</orth>
</form>
<form type="variant" xml:lang="cu">
<orth>а̓бїе</orth>
<form type="hyperlemma" xml:lang="cu">
<orth>абиѥ</orth>
</form>
</form>
<entry>
当我使用以下样式表时
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" xpath-default-namespace="http://www.tei-c.org/ns/1.0" version="2.0">
<xsl:output method="xml" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:param name="replace_orth" select="entry/form[@type='hyperlemma' and @xml:lang='cu']/orth" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="form[@type='variant']/form[@type='hyperlemma' and @xml:lang='cu']/orth/text()">
<xsl:value-of select="$replace_orth" />
</xsl:template>
</xsl:stylesheet>
然后我得到
<form type="variant" xml:lang="cu">
<orth>а̓бїе</orth>
<form type="hyperlemma" xml:lang="cu">
<orth/>
</form>
所以<orth> 是空的。如果我将参数更改为
<xsl:param name="replace_orth" select="'new orth'" />
'new orth' 被打印出来。但由于每个条目的<entry><form type="hyperlemma" xml:lang="cu"><orth> 的内容不同(在上面的示例 XML 中我只显示一个条目),我不能使用“静态”字符串。
我需要改变什么?
感谢任何提示!
【问题讨论】: