SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict AdRock952's Avatar
    Join Date
    Aug 2006
    Posts
    243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Some advice of XSL stylesheets

    I am trying to apply several styles to an XML file using an XSL stylesheet to present the data in several formats.

    Would it be best to have a seperate XSL file for every style of presentation or use one stylesheet and call multiple templates?

    If i was to use one stylesheet how would i call each template for each style?

    I would have thought it would be something like
    Code XML:
    <xsl:template name="styles">
    	<xsl:call-template name="templatename">
     
    	  <!-- This is for my first layout -->
     
    	</xsl:call-template> 
     
    	<xsl:call-template name="templatename">
     
    	  <!-- This is for my second layout -->
     
    	</xsl:call-template> 
     
    	<xsl:call-template name="templatename">
     
    	  <!-- This is for my third layout -->
     
    	</xsl:call-template> 	
    </xsl:template>

  2. #2
    SitePoint Addict AdRock952's Avatar
    Join Date
    Aug 2006
    Posts
    243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry....i couldn't read your reply as there is something wrong with my account and it's preventing your post from being made visible to me.

    I have since worked out that i could import each stylesheet or i can have several templates each calling a set of smaller templates to present my data.

    The question now is, is there a way i can have a menu at the top such as a bunch of hyperlinks and by click each one will call a different template instead of all the templates at once?

    Hopefully when i get a reply i'll be able to read it

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,192
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    I think that was covered in the free sample chapters for this book http://www.sitepoint.com/books/xml1/
    Or maybe it was in this article http://articles.sitepoint.com/articl...troduction-xml

  4. #4
    SitePoint Addict AdRock952's Avatar
    Join Date
    Aug 2006
    Posts
    243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I couldn't see what i was trying to do in either of those links

    What i want to do is have a menu and click a link and the relavent stylesheet will be called

    The way i have it working at the minute does work but the document is too long becasue of the same data being displayed in different formats

    Code XML:
    <xsl:template match="folktask">
      <html>
      <head>
    	<link href="xsl2.css" rel="stylesheet" type="text/css" />
    	<style type="text/css">
    	body {
    	   font-size:0.83em;
    	   font-family:arial;
    	}
    	</style>
       </head>
      <body>
        <h1 id="showAllUSers">Show all users contact details</h1>
     
    	<xsl:call-template name="show_all_users" />
     
    <h2>My festival organisers and festivals</h2>
     <xsl:for-each select="member">
     
    	<xsl:if test="user/account/userlevel='3'">
    	  <xsl:call-template name="organisers"/>
    	</xsl:if>
     </xsl:for-each>
       <xsl:if test="position()=last()">
        <div class="count"><h2>Total number of festival organisers: <xsl:value-of select="count(/folktask/member/user/account/userlevel[text()=3])"/></h2></div>
    	<div class="count"><h2>Total number of festivals: <xsl:value-of select="count(/folktask/member/festival)"/></h2></div>
      </xsl:if>
      </body>
      </html>
    </xsl:template>

  5. #5
    SitePoint Zealot boen_robot's Avatar
    Join Date
    Apr 2008
    Location
    europe://Bulgaria/Plovdiv
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wouldn't say there is a "right" way to do what you want... both ways are equally acceptable.

    What I'd do is that if there are subtle differences in the presentation, I'd embed them in the same stylesheet, and if they're too many, I'd place them in a separate stylesheet.
    XML_XSLT2Processor - perform XSLT 2.0 transformations in PHP.
    (my library, all feedback welcome)


Bookmarks

Posting Permissions

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