Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 30th, 2005, 08:31 AM
Registered User
 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Grouping stand alone nodes inside an element

Hi All

I have an XML file like below:

<head>
<frnt>
<para>some text</para>
<list>some lists</list>
..........
<qes>Question 1</qes>
<ans>Answer 1<ans>
<qes>Question 2</qes>
<ans>Answer 2<ans>
<qes>Question 3</qes>
<ans>Answer 3<ans>
.........
</frnt>
<body>
------
</body>
</head>

As you can see I have the <qes> and <ans> information. I would like to group all those stand alone nodes in to a element called <queans> as shown below.

<head>
<frnt>
<para>some text</para>
<list>some lists</list>

<queans>

<qes>Question 1</qes>
<ans>Answer 1<ans>
<qes>Question 2</qes>
<ans>Answer 2<ans>
<qes>Question 3</qes>
<ans>Answer 3<ans>

</queans>

</frnt>
<body>
------
</body>
</head>


I need to do this using XSTL. I would greatly appreciate any help provided.

Thanks & Regards,
- Bala Krishnan

 
Old December 30th, 2005, 01:35 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<xsl:template match="frnt">
  <xsl:copy-of select="para|list"/>
  <queans>
    <xsl:copy-of select="qes|ans"/>
  </queans>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 30th, 2005, 02:25 PM
Registered User
 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your reply.

However, I would like to bring <para>, <list> nodes without hard-coding it in the xsl style sheet. I would like to take these nodes by order inside the <frnt>

Hope my explanation is clear.

Please help me.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Muenchian Grouping on individual nodes in xslt1.0 sudhish.sikhamani XSLT 9 July 1st, 2008 10:32 AM
Get distinct values on *second* grouping of nodes. MissHenesy XSLT 4 October 23rd, 2006 10:34 AM
Pushing particular Nodes inside an element ROCXY XSLT 2 January 3rd, 2006 12:21 PM
Grouping orphan nodes to paranet elements ROCXY XSLT 2 January 1st, 2006 07:11 AM
Grouping Nodes shoei78 XSLT 3 May 28th, 2004 10:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.