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 29th, 2009, 04:19 AM
Authorized User
 
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to use the following::sibling

Hi everybody,

Need xsl to add the <author> element after the commos and If my <author> element is the last element followed by the tag <title> it should be add dot.

Find the input xml and output as below,

Input xml:

Code:
<authors>
<author>
<surname>Paivio</surname>
<given-name>A</given-name>
</author>
<author>
<surname>Jansen</surname>
<given-name>B</given-name>
</author>
<author>
<surname>Becker</surname>
<given-name>LJ</given-name>
</author>
</authors>
<title>
<maintitle>Comparisons through the mind&#x0027;s eye</maintitle>
</title>
Need output:

Code:
<authors>
<author>
<surname>Paivio</surname>
<given-name>A</given-name>
</author>,
<author>
<surname>Jansen</surname>
<given-name>B</given-name>
</author>,
<author>
<surname>Becker</surname>
<given-name>LJ</given-name>
</author>.
</authors>
<title>
<maintitle>Comparisons through the mind&#x0027;s eye</maintitle>
</title>
Please help me......
Reply With Quote
  #2 (permalink)  
Old April 29th, 2009, 04:57 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="authors">
<xsl:copy>
<xsl:apply-templates select="author"></xsl:apply-templates>
</xsl:copy>
</xsl:template>

<xsl:template match="title">
<xsl:copy-of select="."></xsl:copy-of>
</xsl:template>

<xsl:template match="author">
<xsl:copy-of select="."></xsl:copy-of>
<xsl:if test="position() != last()"><xsl:text>,</xsl:text></xsl:if>
<xsl:if test="position() = last()"><xsl:text>.</xsl:text></xsl:if>
</xsl:template>

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

Thanks for you immediate reply...

but i need one more request as if dot character should be inserted when the last author name after the <title> tag should come, otherwise it will skip to insert the dot character after </author>tag.

any other possibilities is there........?????
Reply With Quote
  #4 (permalink)  
Old April 29th, 2009, 05:23 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

Assuming that you need comma after the last author, only when there is a title, I post this code. Try this:

Code:
<xsl:template match="authors">
<xsl:copy>
<xsl:apply-templates select="author"></xsl:apply-templates>
</xsl:copy>
</xsl:template>

<xsl:template match="title">
<xsl:copy-of select="."></xsl:copy-of>
</xsl:template>

<xsl:template match="author">
<xsl:copy-of select="."></xsl:copy-of>
<xsl:if test="position() != last()"><xsl:text>,</xsl:text></xsl:if>
<xsl:if test="position() = last()">
<xsl:choose>
<xsl:when test="../../authors/following-sibling::title">
<xsl:text>.</xsl:text>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>


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

Thank you so much ............

It's working perfectly.......

Thanks a lot again.
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
Preceding Sibling mphare XSLT 3 March 4th, 2009 11:04 AM
Using preceding-sibling mcanne98 Infopath 0 September 11th, 2008 11:09 PM
following-sibling. hanzelko XSLT 1 February 2nd, 2007 04:11 PM
checking first sibling stavinoha XSLT 2 July 4th, 2006 02:13 AM
MDI Sibling calling Sibling... Nick.Net VB.NET 2002/2003 Basics 1 December 8th, 2003 09:23 PM



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


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