Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Using XSLT to Order Nodes

Reply
Thread Tools

Using XSLT to Order Nodes

 
 
Newbie
Guest
Posts: n/a
 
      07-20-2006
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

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      07-20-2006
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".
 
Reply With Quote
 
 
 
 
Newbie
Guest
Posts: n/a
 
      07-20-2006
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

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      07-20-2006


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
<xslutput 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/
 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      07-20-2006
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.
 
Reply With Quote
 
Newbie
Guest
Posts: n/a
 
      07-20-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting Nodes Using Subtotal of Child Nodes renfrochris@hotmail.com XML 1 08-24-2006 12:30 AM
XSLT: Select nodes in reverse order thrill5 XML 3 05-14-2006 01:10 PM
Text nodes and element nodes query asd Java 3 05-23-2005 10:01 AM
selecting nodes between other nodes Timo Nentwig XML 1 06-17-2004 04:54 AM
Reality check: Is it sensible to link XML nodes to other XML nodes in the same file? gavnosis XML 0 08-02-2003 08:22 AM



Advertisments