Using XSLT to Order Nodes

Discussion in 'XML' started by Newbie, Jul 20, 2006.

  1. Newbie

    Newbie Guest

    The answer to this is probably obvious, but I'm somewhat new to XSLT and can't
    find it.

    I need to sort a set of nodes within a document, e.g.

    <A>
    <B/>
    <C>
    <D>3</D>
    <D>2</D>
    <D>4</D>
    <D>1</D>
    </C>
    <F/>
    </A>

    How should I construct an XSLT to output

    <A>
    <B/>
    <C>
    <D>1</D>
    <D>2</D>
    <D>3</D>
    <D>4</D>
    </C>
    <F/>
    </A>

    where everything outside C is arbitrary? I know about sort, but I don't know how
    to output everything around C.

    Thanks for any help.

    --
    Posted via a free Usenet account from http://www.teranews.com
    Newbie, Jul 20, 2006
    #1
    1. Advertising

  2. Newbie wrote:
    > where everything outside C is arbitrary? I know about sort, but I don't
    > know how to output everything around C.


    Start with the "identity stylesheet", then add a template which will do
    the special handling needed for match="C".
    Joe Kesselman, Jul 20, 2006
    #2
    1. Advertising

  3. Newbie

    Newbie Guest

    Joe Kesselman wrote:
    > Start with the "identity stylesheet", then add a template which will do
    > the special handling needed for match="C".


    Found a reference to "identity stylesheet" in
    http://hacks.oreilly.com/pub/h/2070, but a comment warns about problems with
    CDATA. What is the problem here (I can't find any more info), and is there an
    easy way around it (I can't control the input)?

    --
    Posted via a free Usenet account from http://www.teranews.com
    Newbie, Jul 20, 2006
    #3
  4. Newbie wrote:

    > Found a reference to "identity stylesheet" in
    > http://hacks.oreilly.com/pub/h/2070, but a comment warns about problems
    > with CDATA. What is the problem here (I can't find any more info), and
    > is there an easy way around it (I can't control the input)?


    The XPath/XSLT data model does not know CDATA sections, it only knows
    text nodes. If you transform XML to XML with a simple identity
    transformation then CDATA sections might not be preserved but in terms
    of well-formedness everything will be fine, only instead of having a
    CDATA section to escape things character/entity references will be used
    to escape things.
    You can however define
    <xsl:eek:utput cdata-section-elements="put element names here" />
    to have the XSLT processor create CDATA sections as element contents
    when serializing that result tree.
    That way you can determine which elements in the result should have
    CDATA section content. Only it does not help if you want to write a
    generic stylesheet processing abritary elements you don't know the names of.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jul 20, 2006
    #4
  5. Of course no modern XML application should care whether you've used
    CDATA sections or ordinary text with character-by-character escaping
    when needed.

    Unfortunately some tools carried over from the HTML world are broken in
    that regard.
    Joe Kesselman, Jul 20, 2006
    #5
  6. Newbie

    Newbie Guest

    Martin Honnen wrote:
    > The XPath/XSLT data model does not know CDATA sections, it only knows
    > text nodes. If you transform XML to XML with a simple identity
    > transformation then CDATA sections might not be preserved but in terms
    > of well-formedness everything will be fine, only instead of having a
    > CDATA section to escape things character/entity references will be used
    > to escape things.


    Thank you, hopefully this will suffice.

    --
    Posted via a free Usenet account from http://www.teranews.com
    Newbie, Jul 20, 2006
    #6
    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. asd
    Replies:
    3
    Views:
    437
    Arnaud Berger
    May 23, 2005
  2. gavnosis
    Replies:
    0
    Views:
    519
    gavnosis
    Aug 2, 2003
  3. Timo Nentwig

    selecting nodes between other nodes

    Timo Nentwig, Jun 16, 2004, in forum: XML
    Replies:
    1
    Views:
    402
    Patrick TJ McPhee
    Jun 17, 2004
  4. thrill5
    Replies:
    3
    Views:
    16,179
    Jeff Higgins
    May 14, 2006
  5. Replies:
    1
    Views:
    572
    Soren Kuula
    Aug 24, 2006
Loading...

Share This Page