[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

How to copy attribute value to text?

Subject: How to copy attribute value to text?
From: "Kenneth Reid Beesley krbeesley@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 7 Jul 2016 05:22:26 -0000
 How to copy attribute value to text?
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

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.

<xsl:stylesheet version="2.0"

        <xsl:output method="xml" indent="yes"/>

        <xsl:template match="node()|@*">
                        <xsl:apply-templates select="node()|@*"/>

				<xsl:template match="word[@correction]">

					<xsl:variable name="origtext" select="."/>
					<xsl:variable name="correction">
						<xsl:value-of select="@correction"/>

						<xsl:copy-of select="@*[name()!='correction']"/>
						<xsl:attribute name="origerror" select="$origtext"/>
						<xsl:value-of select="$correction"/>


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

Any help would be much appreciated.

Kenneth R. Beesley, D.Phil.
PO Box 540475
North Salt Lake UT 84054

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.