Xslt: How to change node text in element using a parameter



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:



<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>


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://ift.tt/tCZ8VR" xmlns:xs="http://ift.tt/tphNwY" exclude-result-prefixes="xs" xpath-default-namespace="http://ift.tt/1dDT9n4" 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, I cannot use a 'static' string.


What do I need to change?


Thanks for any hint!


No comments:

Post a Comment