Subject: Re: [xsl] How to copy attribute value to text? From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 7 Jul 2016 06:44:10 -0000 |
If I start with an input XML document that contains mixed text with <word> elements like this:
b& this is just <word correction=btoob>to</word> funny
Ibd like to write an XSLT stylesheet that yields as output
b& this is just <word origerror=btob>too</word> funny
So in the output I effectively want (in the same <word> element) to
1. Set the value of a new attribute to the original text() value, and 2. Reset the text() value to be the value of the original @correction attribute
Ibve tried many variants of the following, so far without success. Ibm using SaxonHE9-7-0-6J; it runs, but the results are not as expected/hoped.
Ibve tried matching the text() in a separate template, but I canbt seem to reference the attribute values of the parent node (i.e., <word>) of the text() and the parent nodebs attributes. E.g, the following doesnbt work for me, failing somehow in the select=b../@correctionb reference.
<xsl:template match=bword[@correction]/text()b> <xsl:value-of select=b../@correctionb/> </xsl:template>
<xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="word[@correction]/text()"> <xsl:value-of select="../@correction"/> </xsl:template> <xsl:template match="word/@correction"> <xsl:attribute name="origerror" select=".."/> </xsl:template>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How to copy attribute value t, Kenneth Reid Beesley | Thread | [xsl] Saxon-CE -- Passing Data to a, Chris Despopoulos de |
[xsl] How to copy attribute value t, Kenneth Reid Beesley | Date | [xsl] Saxon-CE -- Passing Data to a, Chris Despopoulos de |
Month |