Subject: Re: [xsl] ACCESSING SPECIFIC CDATA FIELD From: <viniciuscamara@xxxxxxxxxxxx> Date: Tue, 13 Dec 2005 14:47:44 -0300 |
Thanks Jon and friends, for your explanation about CDATA nodes.
Thank again. Best regards
Hello Fellows, I've one XML and trying to access the specific CDATA on XML but when do this, I capture all CDATAs nodes. See the XML and XSL code bellow:
First of all, there is no such thing as a CDATA node. CDATA is just a nice way to write something so that you don't have to worry about escaping all the < and other special characters. There's only text nodes. So what you really appear to be asking for is a way to select specific text nodes.
And the answer is yes, of course. Just select the text nodes and apply-templates or get their value.
// -----------------------------xml ----------------------------- <?xml version="1.0" encoding="UTF-8"?> <scripts> <etps total="1"> <etp id="200"> <![CDATA[Trying accessing only this]]> <nvgs> <nvg id="201"><![CDATA[blablablablabla]]></nvg> <nvg id="202"><![CDATA[blablablablabla]]></nvg> </nvgs> </etp> </etps> </scripts>
// -----------------------------xsl ----------------------------- //code's resume <xsl:choose> <xsl:when test="scripts/etapas/@total>0"> <table width="100%" id="SCRIPT"> <tr valign="top" style="font-weight:bold;"> <th width="40%">etp</th> <th width="20%">nvg</th> </tr>
<xsl:for-each select="scripts/etapas/etapa"> <tr valign="top"> <td comment="ETP"> <xsl:value-of select="."/><br/> <!--When I put the prefix "." <!--the XSL return all CDATA nodes, including "nvgs"-->
No, it gets the value of the element, which is defined in the specs. A quick summary would be all the text nodes of this element and all the text nodes of its descendents. If you don't want to do that, get <xsl:value-of select="text()" /> although my guess in this case you want to get <xsl:value-of select="text()[1]" />. (or just apply-templates on those if you do anything special with the text).
Is it necessary to create a node to CDATA ?
No, since it'll be turned into just escaped text via the parser. As far as the processor is concerned, it's just a typical text node.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] ACCESSING SPECIFIC CDATA , Jon Gorman | Thread | Re: [xsl] ACCESSING SPECIFIC CDATA , drkm |
RE: [xsl] nesting flat XML based on, Michael Kay | Date | RE: [xsl] ACCESSING SPECIFIC CDATA , Nick Fitzsimons |
Month |