|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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..... |
|
#3
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > copy-of / value-of select |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|