Processing "random" PCDATA


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Processing "random" PCDATA

  1. #1
    Eric Lemasters Guest

    Processing "random" PCDATA


    I have been assigned the task to see if you can reliably transform XHTML into
    XHTML. I need to traverse the tree to apply a template to an element that
    can be several layers in, but essentially copy the rest of the data as is.
    An example would be change the path to an img, but keep the data around
    the image the same. The problem is when there is data that is not contained
    in a child element.

    <div class="DocAuthors">
    <vau>
    <vfau>
    <vfaugiven>Michael</vfaugiven>
    <vfaumiddle>E.</vfaumiddle>
    <vfausur>O&rsquo;Dwyer</vfausur>
    ,
    <vfaudeg>MD</vfaudeg>
    </vfau>
    ; Brian J. Druker, MD
    </vau>
    </div>

    Right now I am doing checks to see if an element has children, if yes, then
    do a check and check if it has children, so on and so on. When I use value-of
    it seems to return the data of the children as well. Is there a way to get
    the text not contained in a child element to format correctly relative to
    the other child elements.

    Thanks for any help

    Eric

  2. #2
    hassan mirza Guest

    Re: Processing "random" PCDATA


    im not sure that i understand what you are trying to ask, but i think:

    <name>Bill</name>
    <name>Brown
    <age>3</age>
    <height>6ft</height>
    </name>
    --------------------
    <xsl:template match="name">
    <xsl:value-of select="."/>
    </xsl:template>

    ---------------------------

    when the first element is matched it will print out:
    bill

    when the second element is matched it will print out:
    Brown36ft

    to prevent the data of the child elements from showing use this

    <xsl:template match="name">
    <xsl:value-of select="text()"/>
    </xsl:template>

    the text() is a child node of any other node. it will only give you the text
    for the current node, if you exlude that in you value-of statment then it
    will give you the text of all the child nodes also.

    i think this is what you were trying to ask. if not please be more specific.

    "Eric Lemasters" <ericlemasters@technotects.com> wrote:
    >
    >I have been assigned the task to see if you can reliably transform XHTML

    into
    >XHTML. I need to traverse the tree to apply a template to an element that
    >can be several layers in, but essentially copy the rest of the data as is.
    > An example would be change the path to an img, but keep the data around
    >the image the same. The problem is when there is data that is not contained
    >in a child element.
    >
    ><div class="DocAuthors">
    > <vau>
    > <vfau>
    > <vfaugiven>Michael</vfaugiven>
    > <vfaumiddle>E.</vfaumiddle>
    > <vfausur>O’Dwyer</vfausur>
    > ,
    > <vfaudeg>MD</vfaudeg>
    > </vfau>
    > ; Brian J. Druker, MD
    > </vau>
    ></div>
    >
    >Right now I am doing checks to see if an element has children, if yes, then
    >do a check and check if it has children, so on and so on. When I use value-of
    >it seems to return the data of the children as well. Is there a way to

    get
    >the text not contained in a child element to format correctly relative to
    >the other child elements.
    >
    >Thanks for any help
    >
    >Eric



  3. #3
    Russell Jones Guest

    Re: Processing "random" PCDATA

    Use the text() function rather than the value-of method to get the text of
    an element without also retrieving its childrens' text.
    Use the count() function to test whether a node has children.
    Use the copy and copy-of methods to copy nodes to the result tree.

    HTH
    Russell Jones
    Sr. Web Development Editor
    DevX.com

    "Eric Lemasters" <ericlemasters@technotects.com> wrote in message
    news:3b2139e8$1@news.devx.com...
    >
    > I have been assigned the task to see if you can reliably transform XHTML

    into
    > XHTML. I need to traverse the tree to apply a template to an element that
    > can be several layers in, but essentially copy the rest of the data as is.
    > An example would be change the path to an img, but keep the data around
    > the image the same. The problem is when there is data that is not

    contained
    > in a child element.
    >
    > <div class="DocAuthors">
    > <vau>
    > <vfau>
    > <vfaugiven>Michael</vfaugiven>
    > <vfaumiddle>E.</vfaumiddle>
    > <vfausur>O&rsquo;Dwyer</vfausur>
    > ,
    > <vfaudeg>MD</vfaudeg>
    > </vfau>
    > ; Brian J. Druker, MD
    > </vau>
    > </div>
    >
    > Right now I am doing checks to see if an element has children, if yes,

    then
    > do a check and check if it has children, so on and so on. When I use

    value-of
    > it seems to return the data of the children as well. Is there a way to

    get
    > the text not contained in a child element to format correctly relative to
    > the other child elements.
    >
    > Thanks for any help
    >
    > Eric




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center