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 May 7th, 2014, 09:58 AM
Authorized User
 
Join Date: Apr 2013
Posts: 31
Thanks: 3
Thanked 0 Times in 0 Posts
Default how to differentiate templates based on cases

Hi i've the below two cases in XML.

Case1:

Code:
<para num="01"><page num="05"/>abcdefghij ancfrgthig</para>
Case2:

Code:
<para num="01">abcdefgrghy sdfdfhrtfd<page num="05"/></para>
Case3:

Code:
<para num="01">abcdefgrghy <page num="05"/>sdfdfhrtfd</para>
Case4:

Code:
<para num="01"><span class="bold">abcdefgrghy sdfdfhrtfd</span><page num="05"/></para>
Case5:

Code:
<para num="01"><span class="bold">abcdefgrghy</span><page num="05"/> sdfdfhrtfd</para>
Case6:

Quote:
<para num="01"><span class="bold">abcdefgrghy</span> sdfdfhrtfd<page num="05"/> </para>
Case7:

Code:
<para num="01"><span class="bold">abcdefgrghy sdfdfhrtfd</span><page num="05"/> </para>
I need to differentiate these two cases, because i want to make different templates for each.

I use directly <xsl:apply-templates/>, but here if i have the first case stated above, first the page template needs to be called by the para template.

Thanks
 
Old May 7th, 2014, 10:04 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Two cases? I see 7...

Please explain your XML and what you ar expecting to happen, I.e. Your expected output.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old May 7th, 2014, 10:30 AM
Authorized User
 
Join Date: Apr 2013
Posts: 31
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Hi Thanks for the reply, actually i've solved this. Thanks again. And here is the solution.

Code:
<xsl:choose>
            <xsl:when test="child::node()[1][self::*]">
													<xsl:apply-templates select="child::page[1]"/>
													  <div class="para">
               <xsl:call-template name="phrase"/>												
                <xsl:apply-templates select="child::node()[not(self::page)]"/>
                </div>
												</xsl:when>  
												
                <xsl:otherwise>
                 <div class="para">
                     <xsl:call-template name="phrase"/>												
                    <xsl:apply-templates/>
                </div>
                </xsl:otherwise>
            </xsl:choose>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting elements accessed via apply-templates based on the real XML tag name in XSLT azikh XSLT 2 August 29th, 2013 07:56 PM
Applying Templates Based on Attributes JoshC XSLT 6 February 21st, 2009 07:31 PM
How to ignore cases on attribute value 2BOrNot2B XSLT 2 January 30th, 2009 12:03 PM
How to differentiate to number lists gilgalbiblewheel Java GUI 0 September 15th, 2004 07:22 PM
How do we differentiate b/w User and Sys tables softwarearchitect SQL Server 2000 5 May 30th, 2004 08:39 AM





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