Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 21st, 2006, 01:39 AM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default combine the nodes

Hi,
I have problem to combine the tags.
Input XML is as follows:

<details>
<detail id="0" onInvoice="true" isCustomerRequest="false">
<text>*</text>
</detail>
<detail id="1" onInvoice="true" isCustomerRequest="false">
<text>Important extra information fort his trip<text>
</detail>
<detail id="2" onInvoice="true" isCustomerRequest="false">
<text>For the diving activities you need a special medical attest </text>
</detail>
<detail id="3" onInvoice="true" isCustomerRequest="false">
 <text>which has to be not older than one year.</text>
</detail>
<detail id="4" onInvoice="true" isCustomerRequest="false">
<text>*</text>
</detail>
</details>

Expected Output:

<details>
<detail id="0" onInvoice="true" isCustomerRequest="false">
<text>*</text>
<text>Important extra information fort his trip<text>
<text>For the diving activities you need a special medical attest </text>
<text>which has to be not older than one year.</text>
<text>*</text>
 </detail>
</details>

Reply With Quote
  #2 (permalink)  
Old February 21st, 2006, 04:56 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It would be useful when people say they "have a problem" if they say what the problem is. If I don't know what you've tried and what concepts you're struggling with, then it's hard to help you over your learning difficulties.

This is really a very simple problem:

<xsl:template match="details">
  <detail>
    <xsl:copy-of select="detail[1]/@*">
    <xsl:copy-of select="detail/text"/>
  </detail>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old April 23rd, 2007, 12:25 PM
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Please help... I want to merge the XML based on some key..

input:
<n1>
 <n2>1</n2>
 <n3>4</n3>
 <n4>5</n4>
</n1>
<n1>
 <n2>1</n2>
 <n3>5</n3>
 <n4>5</n4>
</n1>
<n1>
 <n2>1</n2>
 <n3>6</n3>
 <n4>5</n4>
</n1>
<n1>
 <n2>2</n2>
 <n3>4</n3>
 <n4>5</n4>
</n1>

output:

<n1>
 <n2>1</n2>
 <n3s>
  <n3>4</n3>
  <n3>5</n3>
  <n3>6</n3>
 </n3s>
 <n4>5</n4>
</n1>
<n1>
 <n2>2</n2>
 <n3>4</n3>
 <n4>5</n4>
</n1>

..


Quote:
quote:Originally posted by mhkay
 It would be useful when people say they "have a problem" if they say what the problem is. If I don't know what you've tried and what concepts you're struggling with, then it's hard to help you over your learning difficulties.

This is really a very simple problem:

<xsl:template match="details">
<detail>
    <xsl:copy-of select="detail[1]/@*">
    <xsl:copy-of select="detail/text"/>
</detail>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #4 (permalink)  
Old April 23rd, 2007, 01:11 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Happy81: I'm not sure how your message relates to earlier messages on the same thread or to the message you are quoting.

The problem you've outlined is a standard grouping problem. In XSLT 2.0, use xsl:for-each-group. In XSLT 1.0, use Muenchian grouping as described for example at http://www.jenitennison.com/xslt/grouping

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to combine two forms into one? malhyp Dreamweaver (all versions) 13 June 5th, 2006 07:29 AM
How to combine two value-of selects? myhtpc XSLT 2 February 14th, 2006 06:20 AM
combine two tables dhborchardt Access 2 December 7th, 2004 05:47 PM
combine 2 queries collie SQL Server 2000 2 November 29th, 2004 03:09 PM
Combine queries lryckman Access VBA 2 May 11th, 2004 11:38 AM



All times are GMT -4. The time now is 01:20 AM.


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