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 February 21st, 2006, 01:39 AM
Authorized User
 
Join Date: Feb 2006
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>

 
Old February 21st, 2006, 04:56 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old April 23rd, 2007, 12:25 PM
Registered User
 
Join Date: Apr 2007
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
 
Old April 23rd, 2007, 01:11 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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





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





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