print all subelements plus content

Discussion in 'XML' started by David Simons, Feb 23, 2005.

  1. David Simons

    David Simons Guest

    Hi,

    I don't know how to print out all subcontent of an
    element with xslt. E.g.
    <book>
    <chapter>first chapter
    <content>
    lorem ipsum bla
    </content>
    </chapter>
    <chapter>second chapter
    <content>
    that and this and this and that
    </content>
    </chapter>
    .......
    </book>

    xslt:
    .....
    <xsl:for-each select="book"> <xsl:value-of select="child::*"/>
    </xsl:for-each>
    ....

    But this just gives me the first chapter but none of
    the other chapters, I don't know why?

    Regards,

    David
     
    David Simons, Feb 23, 2005
    #1
    1. Advertising

  2. Hi David,

    I'm guessing that you are new to XSL. To get the most out of it
    requires a change of mind-set and, in my opinion, this requires
    avoiding use of <xsl:for-each> until you get your head around the
    declarative basis of XSLT.

    That aside, to answer your question, what you have done is set the
    document context to the first book element and then selected the child
    axis only for that first book element.

    You would be better off defining a template :-

    <xsl:template match="chapter">
    <xsl:value-of select="content"/>
    </xsl:template>

    and then triggering this by using

    <xsl:apply-templates select="book"/>

    from wherever you want/need to.

    I hope this helps - if you persevere it will pay the same sort of
    dividends as a true understanding of SQL.

    Regards

    David Simons <> wrote in message news:<cvj15s$vka$>...
    > Hi,
    >
    > I don't know how to print out all subcontent of an
    > element with xslt. E.g.
    > <book>
    > <chapter>first chapter
    > <content>
    > lorem ipsum bla
    > </content>
    > </chapter>
    > <chapter>second chapter
    > <content>
    > that and this and this and that
    > </content>
    > </chapter>
    > ......
    > </book>
    >
    > xslt:
    > ....
    > <xsl:for-each select="book"> <xsl:value-of select="child::*"/>
    > </xsl:for-each>
    > ...
    >
    > But this just gives me the first chapter but none of
    > the other chapters, I don't know why?
    >
    > Regards,
    >
    > David
     
    Warrell Harries, Feb 24, 2005
    #2
    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. David Simons

    print all subelements plus content

    David Simons, Feb 23, 2005, in forum: XML
    Replies:
    0
    Views:
    388
    David Simons
    Feb 23, 2005
  2. The LoxFather

    C plus plus vs C Sharp

    The LoxFather, Aug 9, 2003, in forum: C++
    Replies:
    23
    Views:
    9,271
  3. The LoxFather

    C plus plus vs C Sharp

    The LoxFather, Aug 9, 2003, in forum: C Programming
    Replies:
    23
    Views:
    1,412
  4. Rahul
    Replies:
    9
    Views:
    434
    Andrey Tarasevich
    Mar 25, 2008
  5. furqan shaikh

    c plus plus code comparator

    furqan shaikh, Nov 7, 2008, in forum: C++
    Replies:
    6
    Views:
    828
    red floyd
    Nov 12, 2008
Loading...

Share This Page