Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2006, 06:15 PM
Newbie
Guest
 
Posts: n/a
Default Using XSLT to Order Nodes

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

  #2  
Old July 20th, 2006, 06:35 PM
Joe Kesselman
Guest
 
Posts: n/a
Default Re: Using XSLT to Order Nodes

Newbie wrote:
Quote:
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".
  #3  
Old July 20th, 2006, 06:45 PM
Newbie
Guest
 
Posts: n/a
Default Re: Using XSLT to Order Nodes

Joe Kesselman wrote:
Quote:
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

  #4  
Old July 20th, 2006, 07:05 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: Using XSLT to Order Nodes



Newbie wrote:
Quote:
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:output 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/
  #5  
Old July 20th, 2006, 07:35 PM
Joe Kesselman
Guest
 
Posts: n/a
Default Re: Using XSLT to Order Nodes

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.
  #6  
Old July 20th, 2006, 10:15 PM
Newbie
Guest
 
Posts: n/a
Default Re: Using XSLT to Order Nodes

Martin Honnen wrote:
Quote:
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

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles