473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

XSLT: getting text of a node into an attribute

I have a document, lets say:

<Doc>
<Ele1 Att1='hello'>
<Ele2 Att2='goodbye'/>
</Ele1>
</Doc>

In XSLT I need to generate an attribute value which contains part of
this document as a text string, ie:

<MyOutput XML="&lt;Ele1 Att1='hello'>
&lt;Ele2 Att2='goodbye'/>
&lt;/Ele1>"/>
I can output it easily enough at child elements (copy-of), or as a
CDATA string in the element content, but I cannot find any way to get
it into an attribute.

What should I be doing?
Jul 20 '05 #1
4 3137
use

<xsl:attribute name="XML">
<xsl:copy-of ...> (or whatever)
</xsl:attribute>

anything you put inside here will be put into the XML attribute of the node
you're creating

"Kevin" <ke*********@formedix.com> wrote in message
news:1b************************@posting.google.com ...
I have a document, lets say:

<Doc>
<Ele1 Att1='hello'>
<Ele2 Att2='goodbye'/>
</Ele1>
</Doc>

In XSLT I need to generate an attribute value which contains part of
this document as a text string, ie:

<MyOutput XML="&lt;Ele1 Att1='hello'>
&lt;Ele2 Att2='goodbye'/>
&lt;/Ele1>"/>
I can output it easily enough at child elements (copy-of), or as a
CDATA string in the element content, but I cannot find any way to get
it into an attribute.

What should I be doing?

Jul 20 '05 #2

Unfortunately not, I already tried that. For some reason nothing comes
through in the attribute if I do <copy-of>. I just end up with an empty
attribute.

I'm guessing copy-of outputs a nodeset rather than a string, hence you
can't stick it into an attribute value.

Any other ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
looking at your original post, I see that I misunderstood what you meant by
'text of a node'. in XML, text is stuff that isn't inside an element or
comment. what you wanted was a textual representation of an element i.e.
with the angle brackets in.

The angle bracket notation is something that is used to serialise XML so
that it can be saved or viewed, but programs that process XML (including the
XSLT processor) don't see the angle brackets when doing the processing; they
are working with a tree of nodes. The angle brackets are only added on at
the end if you're using an output method that requires them.

So what I'm sating is that if you want to include a piece of serialized XML
in the output document you'll have to do it yourself. something like:

<xsl:template match="Doc/*">
<xsl:element name="MyOutput">
<xsl:attribute name="XML">
&lt;
<xsl:value-of select="name()"/>
<xsl:for-each select="@*">
 
<xsl:value-of select="name()"/> = &quot;<xsl:value-of
select="text()/>&quot;
&gt;
</xsl:attribute>
</xsl:element>
</xsl:template>

this is untested but I think it should give you the idea

Andy

"Kevin Burges" <ke***@burieddreams.com> wrote in message
news:3f*********************@news.frii.net...

Unfortunately not, I already tried that. For some reason nothing comes
through in the attribute if I do <copy-of>. I just end up with an empty
attribute.

I'm guessing copy-of outputs a nodeset rather than a string, hence you
can't stick it into an attribute value.

Any other ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #4


Thanks for your help, that sounds like it will probably do the trick. I
thought I might have to do something like that, but I was hoping there
would be a way around it.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron...
1
by: Johannes Lebek | last post by:
Hi there, somehow, I cannot access nodes that are stored in a variable. I'm using Xalan 2.5.1 and the following commands: ================ BEGIN ==================== <xsl:variable...
9
by: Iain | last post by:
I want to create an XML configuration file which might look like <REGION Name="Europe" WingDing="Blue"> <COUNTRY Name="UK" WingDing="white"> <TOWN Name="London" WingDing="Orange" /> </COUNTRY>...
3
by: Eyal | last post by:
Hello, I am new to xslt and try to have an argument that for each iteration of the "FOR-EACH" will grow in one: <xsl:for-each select="//AssetCode"> <node id="_1"> <xsl:attribute name="text">...
1
by: Bartek | last post by:
Hello This is my problem: It consider xml 2 xml conversion. source document had unknown structure (xhtml), xslt must process every node, attribute, text, comments etc. from source and write in...
3
by: rush | last post by:
I have a DTD that defines new elements "mytextfield" and "mysn", and does it as an extension to XHTML. The idea is that my XML markup is actually valid XHTML according to my DTD. This all works...
3
by: Stephan Brunner | last post by:
Hi I have created two flavors of an XSLT stylesheet to transform all attributes of an XML document to elements: They both work as expected with MSXML and XMLSPY but throw an exception ...
2
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.