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 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......
 
Old April 29th, 2009, 04:57 AM
Friend of Wrox
 
Join Date: Jun 2008
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
 
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........?????
 
Old April 29th, 2009, 05:23 AM
Friend of Wrox
 
Join Date: Jun 2008
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
 
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.





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





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