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 24th, 2009, 06:12 AM
Authorized User
 
Join Date: Jul 2008
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Default xslt problem

hello sir

i got a problem with <author>, i have to give the output according to order of childs of author, how to do that with xslt


input:
<author>
<surname>Goldoft</surname><x> </x><fname>M</fname>
</author>,
<author>
<fname>PM</fname><x> </x><surname>Griffin</surname>
</author>



output:
<name-inverted>
<surname>Goldoft</surname> <given-names>M</given-names>
</name-inverted>,
<name>
<given-names>PM</given-names> <surname>Griffin</surname>
</name>


thanks
rajashekhara
 
Old February 24th, 2009, 06:53 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Something like this:

<xsl:template match="author[1]">
<name-inverted>
<xsl:apply-templates/>
</name-inverted>
</xsl:template>

<xsl:template match="author[position() > 1]">
<name>
<xsl:apply-templates/>
</name>
</xsl:template>

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

<xsl:template match="fname">
<given-names><xsl:value-of select="."/></given-names>
</xsl:template>

<xsl:template match="x">
<xsl:value-of select="."/>
</xsl:template>

This assumes the first author is always "inverted", and the others aren't. An alternative test that's sensitive to the actual content is

<xsl:template match="author[*[1][self::surname]]">

which tests whether the first child element is a surname element.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old February 24th, 2009, 07:29 AM
Authorized User
 
Join Date: Jul 2008
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Default

sir we have to check whether <author> contains <surname> which comes before <fname> or after <fname>

and one more thing is <author> may contains any other tags like "middle-name, coresp-link, affiliation-link, footnote-link etc," that may comes anywhere in the <author> tag, at the beginning or at the end or in between <surname> and <fname>

thanks
Rajashekhara
 
Old February 24th, 2009, 08:09 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>we have to check whether <author> contains <surname> which comes before <fname> or after <fname>

Try two rules with:

match="author[surname/following-sibling::fname]"

match="author[surname/preceding-sibling::fname]"

>and one more thing is <author> may contains any other tags like "middle-name,

That's the beauty of template rules. Just add a template rule for each element that might be encountered.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old February 24th, 2009, 08:16 AM
Authorized User
 
Join Date: Jul 2008
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Default

thanks very much
its working





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT problem with IE 7 asadallahi BOOK: Professional Ajax ISBN: 978-0-471-77778-6 3 April 9th, 2009 09:33 AM
xslt problem mickhughes XSLT 3 March 28th, 2008 05:09 AM
XSLT problem her_today XSLT 1 October 23rd, 2006 11:09 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
XSLT problem pendyalap XSLT 4 March 24th, 2006 04:08 PM





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