473,796 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Jul 20 '06 #1
5 2045
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".
Jul 20 '06 #2
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

Jul 20 '06 #3


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: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/
Jul 20 '06 #4
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.
Jul 20 '06 #5
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

Jul 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2713
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron extension responsible for the xslt functions. The problem i have is that the obtained transformation is not the waited one. I try to proccess the same XML file with XSL file with a program called XMLspy and i obtained the desire and waited...
5
19368
by: K. N. | last post by:
Is there any good and fast Python module for XSLT processing ? I'm going to use XML and XSLT to generate web pages, so I need XSLT processor that will be able to transform for example a DOM object in memory - I don't want to create XML file containing data and then load it and transform with XSLT, but I want to do this at once - without writing to a temporary file. Actually I've seen alot articles about parsing XML, but nothing about...
6
2934
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for this, and came across a problem that I haven't been able to solve elegantly. The problem is to find "linker" vertexes that a pair of verteces from a pre-defined set. For example, if the graph verteces represent cities and edges represent flights...
4
8120
by: cyclops | last post by:
I'm trying to do XML + XSLT -> Another XML. The source XML contains multiple namespaces and XSLT will handle all possible tags under each name space. ----source---- <document xmlns="..." xmlns:a="..." xmlns:b=""> .... ----XSLT---- ....
4
1833
by: Chris Kettenbach | last post by:
Hi Peter, I get error when processing the stylesheet. It errors here. <xsl:for-each select="registration)=1]"> specifically: Expression does not return a DOM node. registration)=1]<--
2
1843
by: Jon Martin Solaas | last post by:
Hi, I have a general document somewhat like this: -------------------------------------- <root> <level1> <level2> <interestingstuff number="2"/> <interestingstuff number="3"/> <interestingstuff number="1"/>
1
1274
by: Foxpointe | last post by:
Given some arbitrary XHTML, I'd like to obtain a 'simplified' XHTML result which strips out a large subset of standard elements and attributes - but not all. The main things I would like to accomplish: 1) Provide a list of elements/attributes to be stripped (i.e. everything else should be passed through) or those that should be passed through (i.e. everything else should be stripped) which would be applied recursively. 2) If an element...
1
3655
by: Daniel Hilgarth | last post by:
Hello, I am currently trying to use XSLT for the creation of multiple HTML-files from a single XML-File. This HTML-files need to have links to each other. The following information might be important: There are some special nodes that will start a new HTML-page ("page-nodes"). Those nodes can be nested. Those nodes have an attribute "name" which is not necessarily unique. There are another special nodes that will create a link in one...
6
4343
by: kluge.wolfram | last post by:
Hi, i get stucked on a transformation problem using XSLT. What i need is to copy an XML Tree to an output XML without any automatic changes. Since i used <xsl:copyor <xsl:copy-ofthere occur unwanted side effects. For example i just copied a xml were several namespace declarations are present more than one time. Then the transformation do remove the declaration at the child nodes. Another funny automatism is - if i remove a node
0
9679
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.