Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2008
    Posts
    76
    Thanks
    6
    Thanked 6 Times in 6 Posts

    Grouping XSL Templates

    Hi again guys posted quite recently i know but i have another question that is related to my other post found here http://www.codingforums.com/showthread.php?t=154446 it seems diffrent enough though that it should have its own Thread

    Would it be possible to to group templates like theses

    Code:
    	<xsl:template match="section">
    		<h2>
    			<xsl:value-of select="title" />
    		</h2>
    		<xsl:apply-templates select="body/paragraph"/>
    	</xsl:template>
    	
    	<xsl:template match="body/paragraph">
    		<p>
    			<xsl:copy-of select="." />
    		</p>
    	</xsl:template>
    into a group because i have serveral diffrent goups that require the same wording but diffrent layouts. For example the above example is the template "index" but i need one for faq and other ones just wondering if its possible?

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes"/>
    	<xsl:template match="/">
    		<html xmlns="http://www.w3.org/1999/xhtml">
    			<head>
    				<title>
    					
    				</title>
    				<meta http-equiv="Content-Language" content="English" />
    				<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    				<meta name="author" content=".com" />
    				<meta name="description" content="counter strike source servers" />
    				<meta name="keywords" content=",counter,strike,source,servers,australia,brisbane" />
    				<meta name="Robots" content="index,follow" />
    				<link rel="stylesheet" type="text/css" href="css/main.css" media="screen" />
    			</head>
    			<body>
    				<div id="hd">
    					<ul>
    						<li id="logo">
    							<a href="http://.com" title="Go to Home page">
    								
    							</a>
    						</li>
    					</ul>
    				</div>
    				<div id="ct">
    					<div id="ctr">
    						<dl>
    							<dt>
    								<strong>
    									Counter Strike:Source Special
    								</strong>
    							</dt>
    							<dd>
    								<br />
    								Get the &quot;&quot; tag removed from your server name
    								absolutely free if you signup now!
    								<br />
    								<span class="termsapply">
    									* Terms and conditions may apply
    								</span>
    								<br />
    							</dd>
    						</dl>
    						<h2>
    							Ping Test Server
    						</h2>
    						<ol>
    							<li>
    								<strong>
    									Server Name
    								</strong>
    								: .com // Ping Test
    							</li>
    							<li>
    								<strong>
    									Max Players
    								</strong>
    								: 4
    							</li>
    							<li>
    								<strong>
    									Map
    								</strong>
    								: de_aztec
    							</li>
    						</ol>
    						<div style="text-align: center">
    							<a href="steam://connect/202.60.72.168:27015/">
    								<strong>
    									Connect
    								</strong>
    							</a>
    						</div>
    						<br />
    						<h2>
    							Random Testimony
    						</h2>
    						<div style="text-align: center">
    							im surprised ur servers run my zombie mod server so good. ty
    							<br />
    							<br />
    							<span class="trueblack">
    								Written By: REC. John Doyle
    							</span>
    						</div>
    					</div>
    					<ul id="men">
    						<li id="m1">
    							<a href="index.php" title="" class="act">
    								Home
    							</a>
    						</li>
    						<li id="m2">
    							<a href="forum.php" title="">
    								Forums
    							</a>
    						</li>
    						<li id="m3">
    							<a href="order.php" title="">
    								Order
    							</a>
    						</li>
    						<li id="m4">
    							<a href="faq.php" title="">
    								FAQ
    							</a>
    						</li>
    						<li id="m5">
    							<a href="contact.php" title="">
    								Contact
    							</a>
    						</li>
    					</ul>
    					<div id="ctc">
    						<h1>
    							<xsl:value-of select="/document/title" />
    						</h1>
    						<xsl:for-each select="/document/body/paragraph">
    							<p>
    								<xsl:copy-of select="." />
    							</p>
    						</xsl:for-each>
    						<xsl:apply-templates select="document/section[@template = 'index']" />
    					</div>
    				</div>
    				<div id="ft">
    					Copyright 2008 .com. 
    				</div>
    			</body>
    		</html>
    	</xsl:template>
    	
    	<xsl:template match="section">
    		<h2>
    			<xsl:value-of select="title" />
    		</h2>
    		<xsl:apply-templates select="body/paragraph"/>
    	</xsl:template>
    	
    	<xsl:template match="body/paragraph">
    		<p>
    			<xsl:copy-of select="." />
    		</p>
    	</xsl:template>
    </xsl:stylesheet>
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="untitled.xsl"?>
    <document>
    	<title>
    		Welcome
    	</title>
    	<body>
    		<paragraph>
    			<strong>
    				Welcome to , an Australian based game server provider.
    			</strong>
    			<br />
    			We supply the gaming community of Australia with high bandwidth, low latency quality servers at competitive prices.
    			<br />
    			We could say we are one of the best server providers in Australia, like all those other companies do but we believe in honesty at . If there is a server problem, we won't beat around the bush, instead we will let you know and get it fixed right away!
    			<br />
    			<br /> 
    			Everyone wants the best server they can get for their money, but do you know what to look for? Contact our support team and let us know about the plans for your server and we will let you know what kind of services you require, whether we offer it or not.
    			<br />
    		</paragraph>
    	</body>
    	<section template='index'>
    		<title>
    			New Service - Left4Dead
    		</title>
    		<body>
    			<paragraph>
    				We are excited to announce we will be offering servers for the upcoming Zombie game powered by Valve, called Left4Dead. If you signup for a server with us within 7 days after the Left4Dead launch, you'll get slots for only $3 each! Left4Dead is due to be released on November 17th 2008, you can preorder it now off of Steam.
    			</paragraph>
    		</body>
    	</section>
    	<section template='index'>
    		<title>
    			Site Launch
    		</title>
    		<body>
    			<paragraph>
    				As many of you have noticed the website has been revamped with a stylish new look, hope you all enjoy it and find it easy enough to navigate.
    			</paragraph>
    		</body>
    	</section>
    	<section template='faq'>
    		<title>
    			How long does it take to setup my server?
    		</title>
    		<body>
    			<paragraph>
    				While we try to have all servers setup the minute payment has been received, it can take anywhere up to 24 hours for your server to be created. You'll receive an email once it is online containing all the information you need.
    			</paragraph>
    		</body>		
    	</section>
    </document>
    Last edited by kieran491; 12-18-2008 at 07:16 AM.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by kieran491 View Post
    Hi again guys posted quite recently i know but i have another question that is related to my other post found here http://www.codingforums.com/showthread.php?t=154446 it seems diffrent enough though that it should have its own Thread

    Would it be possible to to group templates like theses

    Code:
    	<xsl:template match="section">
    		<h2>
    			<xsl:value-of select="title" />
    		</h2>
    		<xsl:apply-templates select="body/paragraph"/>
    	</xsl:template>
    	
    	<xsl:template match="body/paragraph">
    		<p>
    			<xsl:copy-of select="." />
    		</p>
    	</xsl:template>
    into a group because i have serveral diffrent goups that require the same wording but diffrent layouts. For example the above example is the template "index" but i need one for faq and other ones just wondering if its possible?
    I'm not sure I understand. You want to use this two templates for both section, 'index' and 'faq'?

    in that case you need only to change the xpath in apply-template, for this case instead of:

    Code:
    <xsl:apply-templates select="document/section[@template = 'index']" />
    you use:
    Code:
    <xsl:apply-templates select="document/section[@template = 'index' or @template = 'faq']" />
    or if you want to process any section element from xml no matter what is the template attribute:

    Code:
    <xsl:apply-templates select="document/section" />
    best regards

  • #3
    New Coder
    Join Date
    Jun 2008
    Posts
    76
    Thanks
    6
    Thanked 6 Times in 6 Posts

    Post

    i would like diffrent templates groups so say i have on for index i would want this
    Code:
    <index>
    	<xsl:template match="section">
    		<h2>
    			<xsl:value-of select="title" />
    		</h2>
    		<xsl:apply-templates select="body/paragraph"/>
    	</xsl:template>
    	
    	<xsl:template match="body/paragraph">
    		<p>
    			<xsl:copy-of select="." />
    		</p>
    	</xsl:template>
    </index>
    and another for faq
    Code:
    <faq>
    	<xsl:template match="section">
    		<strong>
    			<xsl:value-of select="title" />
    		</strong>
    		<xsl:apply-templates select="body/paragraph"/>
    	</xsl:template>
    	
    	<xsl:template match="body/paragraph">
    		<span id="faq">
    			<xsl:copy-of select="." />
    		</span>
    	</xsl:template>
    </faq>

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Code:
    	<xsl:template match="section" mode="index">
    		<h2>
    			<xsl:value-of select="title" />
    		</h2>
    		<xsl:apply-templates select="body/paragraph"/>
    	</xsl:template>
    	
    	<xsl:template match="body/paragraph" mode="index">
    		<p>
    			<xsl:copy-of select="." />
    		</p>
    	</xsl:template>
    
    	<xsl:template match="section" mode="faq">
    		<strong>
    			<xsl:value-of select="title" />
    		</strong>
    		<xsl:apply-templates select="body/paragraph"/>
    	</xsl:template>
    	
    	<xsl:template match="body/paragraph" mode="faq">
    		<span id="faq">
    			<xsl:copy-of select="." />
    		</span>
    	</xsl:template>
    and apply-templates become:
    Code:
    <xsl:apply-templates select="section" mode="index"/>
    <xsl:apply-templates select="section" mode="faq"/>
    best regards

  • Users who have thanked oesxyl for this post:

    kieran491 (12-18-2008)

  • #5
    New Coder
    Join Date
    Jun 2008
    Posts
    76
    Thanks
    6
    Thanked 6 Times in 6 Posts
    Thanks for that really helped

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by kieran491 View Post
    Thanks for that really helped
    you are welcome,

    best regards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •