xsl-list
[Top] [All Lists]

Re: ACCESSING SPECIFIC CDATA FIELD

2005-12-13 10:47:44
Thanks Jon and friends,
for your explanation about CDATA nodes.

Well, I tried to use your idea "<xsl:value-of select="text()[1]" />" to access the text inside the node <etp id="200"> (see the code bellow), and spected this return: "Trying accessing only this", but returned empty to me.

When I put the prefix "." return to me "Trying accessing only this" + "blablablablabla" + "blablablablabla", with your descedents.

Is it necessary to use the node to separate the texts inside the node? Well, refferering your explanation I think not.
Are there another choice?

My code are parsed using Javascript and open it at Firefox.

Thank again.
Best regards



----- Original Message ----- From: "Jon Gorman" <jonathan(_dot_)gorman(_at_)gmail(_dot_)com>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Tuesday, December 13, 2005 12:17 PM
Subject: Re: [xsl] ACCESSING SPECIFIC CDATA FIELD


On 12/13/05, viniciuscamara(_at_)yahoo(_dot_)com(_dot_)br <viniciuscamara(_at_)yahoo(_dot_)com(_dot_)br> wrote:
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.

Jon Gorman

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


        

        
                
_______________________________________________________ Yahoo! doce lar. Faça do Yahoo! sua homepage. http://br.yahoo.com/homepageset.html


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--