XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old August 29th, 2003, 03:01 AM
ppeou ppeou is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 1 ppeou User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
copy-of / value-of select

hello,

i have an xml node with some html tags within it:
<myNode>This is <b>bold</b> and this is <i>italics</i> in HTML.</myNode>

i want to copy everything in the node, EXCEPT the node name.
if i use <xsl:copy-of select="myNode" />

my result is:
<myNode>This is <b>bold</b> and this is <i>italics</i> in HTML.</myNode>

(* as you can see, copy-of copies everything including the node element)

as for a note, if i use
<xsl:value-of select="myNode" disable-output-escaping="no" />
<xsl:value-of select="myNode" disable-output-escaping="yes" />
<xsl:value-of select="myNode"/>

the HTML tags are lost, so i would only get:
This is bold and this is italics in HTML.

is there a way to only get?:
This is <b>bold</b> and this is <i>italics</i> in HTML.

so that <myNode> </myNode> are not in the return string, and the html tags are part of the return string just like in the example from above.

Reply With Quote
  #2  
Old September 2nd, 2003, 01:36 AM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
Can't say i work with XSL, but maybe this can give you an idea. but the text element is actually a child of the node
so if this is your element is actually called myNode
<myNode>This is <b>bold</b> and this is <i>italics</i> in HTML.</myNode>

this is the child of myNode:
This is <b>bold</b> and this is <i>italics</i> in HTML.

so work with the child node of myNode instead of working with the myNode directly.

If <myNode> is just part of the PCData then i have no clue how to get ride of it, maybe try doing a substring(8,mynode.firstChild.length-10) or a split or something.....

Reply With Quote
  #3  
Old September 3rd, 2003, 09:11 AM
hhibo hhibo is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 8 hhibo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The answer is actually quite simple, but I'agree that the logic of copy / copy-of is somewhat tricky in xsl. Here is the template you need:

<xsl:template match="myNode">
<xsl:copy-of select="text()|*"/>
</xsl:template>

The copy-of will copy the text-nodes of the element 'myNode' as well as all of its children elements (including their children).

NB! As I'm sure you know, most xsl-parsers will have a built-in default that copies all text nodes that has not been matched before. To override this default you also need this template:

<xsl:template match="text()">
</xsl:template>

If the transformation you describe in your message is the only thing you are doing in this stylesheet, you may use the default (and not put in the text-template above) and the only templates you will then need is this:

<xsl:template match="i | b">
<xsl:copy-of select="."/>
</xsl:template>

The rest of the text (outside the i and the b) will be copied automatically by the built-in default.

Bente

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > copy-of / value-of select


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway