I need to change the text of certain nodes, similar to Update the text of an element with XSLT based on param.
This is my 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>
I now want to replace the text between <orth>
in
<form type="variant" xml:lang="cu">
<orth>а̓бїе</orth>
<form type="hyperlemma" xml:lang="cu">
<orth>а̓бїе</orth>
</form>
</form>
by the content of <orth>
in the previous node
<entry>
<form type="hyperlemma" xml:lang="cu">
<orth>абиѥ</orth>
</form>
in order to get the following output:
<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>
When I use the following stylesheet
<?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>
then I get
<form type="variant" xml:lang="cu">
<orth>а̓бїе</orth>
<form type="hyperlemma" xml:lang="cu">
<orth/>
</form>
So <orth>
is empty. If I change the parameter to
<xsl:param name="replace_orth" select="'new orth'" />
'new orth' gets printed. But as the content of <entry><form type="hyperlemma" xml:lang="cu"><orth>
is different for each entry (in the sample XML above I only show one entry), I cannot use a 'static' string.
What do I need to change?
Thanks for any hint!