XSLT: outputting element contents without containing tags

Discussion in 'XML' started by Francis Hwang, Dec 20, 2003.

  1. Hi,

    Maybe this is a newbie question, but: Is there a way to output an
    element's contents -- including contained nodes and free-form text --
    without the containing tags?

    I can imagine that this request might be against the spirit of XML in
    general, but the reason I'm trying to do this is that I want to use
    XSLT for simple generation of XHTML. Basically I want the page's
    contents in external files, then I want to include them into a wrapper
    of the basics (header info, site navigation, etc.) using XSLT. (Of
    course you could also just use something else like server-side
    includes for this but I like the idea of XSLT implicitly forcing
    well-formedness on the documents it processes.) So I have an XSL file
    that looks like:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xsl:version="1.0">
    <head>
    <title>My web site</title>
    </head>
    <body>
    <p id="page_head">
    <!--- page header graphic --->
    </p>
    <hr />
    <div id="page_content">
    <xsl:copy-of select="page_content" />
    </div>
    <div id="site_nav">
    <!--- site navigation --->
    </div>
    </body>
    </html>

    and I want to be able to process a bunch of different files where I
    know nothing about them except for that their root element is
    <page_content>. Could be:

    <page_content>nothing much here.</page_content>

    or

    <page_content>Here's the list of every book I ever read:
    <ol>
    <li><cite>Ulysses</cite> by James Joyce</li>
    <!--- more books --->
    </ol>
    </page_content>

    xsl:value-of strips out any contained tags. xsl:copy-of retains all
    the contained XML tags, but it also keeps the <page_content> tag, of
    course, meaning that it shows up in the final XHTML. Is there a way to
    say "whatever's in this element, include it all in order, but don't
    actually include 'page_content' at the beginning or the end" ?

    Thanks in advance,
    Francis
    Francis Hwang, Dec 20, 2003
    #1
    1. Advertising

  2. Re: outputting element contents without containing tags

    "Francis Hwang" <> wrote in message
    news:...
    > Hi,
    >
    > Maybe this is a newbie question, but: Is there a way to output an
    > element's contents -- including contained nodes and free-form text --
    > without the containing tags?


    <xsl:copy-of select="node()"/>

    will produce all node-children of the current node.


    Dimitre Novatchev.
    FXSL developer, XML Insider,

    http://fxsl.sourceforge.net/ -- the home of FXSL
    Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
    Dimitre Novatchev, Dec 20, 2003
    #2
    1. Advertising

  3. In article <>,
    Francis Hwang <> wrote:

    % Maybe this is a newbie question, but: Is there a way to output an
    % element's contents -- including contained nodes and free-form text --
    % without the containing tags?

    [...]

    Instead of

    % <xsl:copy-of select="page_content" />

    try

    <xsl:copy-of select="page_content/node()" />

    --

    Patrick TJ McPhee
    East York Canada
    Patrick TJ McPhee, Dec 20, 2003
    #3
  4. (Patrick TJ McPhee) wrote in message news:<bs2m9o$sqq$>...
    > In article <>,
    > Francis Hwang <> wrote:
    >
    > % Maybe this is a newbie question, but: Is there a way to output an
    > % element's contents -- including contained nodes and free-form text --
    > % without the containing tags?
    >
    > [...]
    >
    > Instead of
    >
    > % <xsl:copy-of select="page_content" />
    >
    > try
    >
    > <xsl:copy-of select="page_content/node()" />


    Ah, that helps, thanks. Now all the elements inside of page_content
    are showing up, but they're getting xmlns attributes. Instead of <p> I
    get <p xmlns="">. What should I do to stop those from showing up?

    Francis
    Francis Hwang, Dec 21, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lemming
    Replies:
    3
    Views:
    435
    Lemming
    Oct 20, 2004
  2. Don Adams
    Replies:
    1
    Views:
    592
    Martin Honnen
    Mar 5, 2004
  3. S??rgio Nunes

    Outputting "<?" with XSLT

    S??rgio Nunes, Jul 12, 2004, in forum: XML
    Replies:
    2
    Views:
    363
    Martin Honnen
    Jul 12, 2004
  4. jamesd

    data containing html tags appears in gridview

    jamesd, Jun 2, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    340
    Ben Schumacher
    Jun 2, 2006
  5. Kamarulnizam Rahim
    Replies:
    4
    Views:
    216
    Robert Klemme
    Jan 28, 2011
Loading...

Share This Page