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 April 23rd, 2009, 11:39 AM
Authorized User
 
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Swap the element

Hi all,

I need to swap the element like <date> element moved to <volume-nr> before, Is possible to do in xslt.....

Sample xml:

Code:
<issue>
<series>
<volume-nr>37</volume-nr>
</series>
<issue-nr>2</issue-nr>
<date>1975</date>
</issue>
Sample Change Format:

Code:
<issue>
<series>
<date>1975</date>
<volume-nr>37</volume-nr>
</series>
<issue-nr>2</issue-nr>
</issue>
I am using the xsl as below,

Code:
<xsl:template match="issue">
    <xsl:copy>
      <xsl:apply-templates select="@* | node() except (volume-nr, date)"/>
      <xsl:apply-templates select="date, volume-nr"/>
    </xsl:copy>
  </xsl:template>
It not able to swap the element exactly. Please help me ........

Thanks,
Nagaraj
Reply With Quote
  #2 (permalink)  
Old April 24th, 2009, 03:54 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Try this:

Code:
 
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="date"></xsl:template>

<xsl:template match="series">
<xsl:copy>
<xsl:copy-of select="../date"></xsl:copy-of>
<xsl:apply-templates></xsl:apply-templates>
</xsl:copy>
</xsl:template>

__________________
Rummy
Reply With Quote
  #3 (permalink)  
Old April 25th, 2009, 11:42 AM
Authorized User
 
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks you so much,

in this style sheet don't work this structure of xml,

Code:
<issue>
<series>
<title>
<maintitle>The author</maintitle>
</title>
<volume-nr>37</volume-nr>
</series>
<issue-nr>2</issue-nr>
<date>1975</date>
</issue>
Duplicate value of <date>1975></date> present in the out xml file when using the xslt before you posted.

Please guide me!!!!!!

Last edited by Nagaraj; April 25th, 2009 at 12:14 PM..
Reply With Quote
  #4 (permalink)  
Old April 27th, 2009, 01:12 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

For the above input xml, the above code [xslt 2.0], gives the below output.

Code:
<issue>
<series>
<date>1975</date>
<title>
<maintitle>The author</maintitle>
</title>
<volume-nr>37</volume-nr>
</series>
<issue-nr>2</issue-nr>

</issue>


If this is not what you want, then post the needed output.
__________________
Rummy
Reply With Quote
  #5 (permalink)  
Old April 27th, 2009, 01:35 AM
Authorized User
 
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry for missing to mentioned the details,

need the out put like below coding.

<issue>
<series>
<title>
<maintitle>The author</maintitle>
</title>
<date>1975</date>
<volume-nr>37</volume-nr>
</series>
<issue-nr>2</issue-nr>

</issue>

After title element the <date> tag should come in the out put xml ........
Reply With Quote
  #6 (permalink)  
Old April 27th, 2009, 01:44 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Try this:

Code:
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="date"></xsl:template>

<xsl:template match="series">
<xsl:copy>
<xsl:apply-templates></xsl:apply-templates>
</xsl:copy>
</xsl:template>

<xsl:template match="volume-nr">
<xsl:copy-of select="../../date"></xsl:copy-of>
<xsl:copy-of select="."></xsl:copy-of>
</xsl:template>

__________________
Rummy
Reply With Quote
  #7 (permalink)  
Old April 27th, 2009, 02:13 AM
Authorized User
 
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your codings....

Your xsl working with the copy of (to make the duplicate in the out xml), I need to move the <date> element and traverse the <date> element to add the tag afer commas..

I use your above xsl code as below,
<xsl:template match="volume-nr">
<xsl:copy-of select="../../date"></xsl:copy-of>
<xsl:copy-of select="."></xsl:copy-of>
</xsl:template>
the output xml code as below,

Code:
<issue>
<series>
<title>
<maintitle>Cognition</maintitle>
</title>
<date>1975</date><volume-nr>37</volume-nr>
</series>
(<issue-nr>2</issue-nr>): 
<date>1975</date>
</issue>
Any method to avoid the duplicate element creation?????
Reply With Quote
  #8 (permalink)  
Old April 27th, 2009, 02:28 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

With the below input

Code:
<issue>
<series>
<title>
<maintitle>The author</maintitle>
</title>
<volume-nr>37</volume-nr>
</series>
<issue-nr>2</issue-nr>
<date>1975</date>
</issue>
the output produced is

Code:
<issue>
<series>
<title>
<maintitle>The author</maintitle>
</title>
<date>1975</date><volume-nr>37</volume-nr>
</series>
<issue-nr>2</issue-nr>
</issue>
using the code I posted. If it is not what you expected, then post the exact input xml and xslt code you are using.
__________________
Rummy
Reply With Quote
  #9 (permalink)  
Old April 28th, 2009, 04:30 AM
Authorized User
 
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help,

Your code is working fine. my problem is use the below code the <date> tag making to duplicate in the out xml.

Code:
<xsl:template match="date">
<xsl:next-match/>
<xsl:text> </xsl:text>
</xsl:template>
i found the solution as the below code:

Code:
<xsl:template match="volume-nr">
<xsl:copy-of select="../../date"/>
<xsl:text> </xsl:text>
<xsl:copy-of select="."/>
</xsl:template>
Again thanks for you help.
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
how to swap the table column value shahidmca SQL Language 2 July 31st, 2007 06:43 PM
Swap Images Mike707 Dreamweaver (all versions) 3 December 18th, 2006 01:05 PM
swap image onclick The Beginner Javascript How-To 2 November 8th, 2006 08:42 AM
Problem to Swap two number in C# furqanms C# 1 June 5th, 2006 05:12 PM
How to Swap two integers without temp variable ramk_1978 C# 2 February 28th, 2006 08:03 PM



All times are GMT -4. The time now is 02:30 PM.


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