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 August 11th, 2009, 08:49 AM
Authorized User
 
Join Date: Mar 2009
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default need sample xsl

Dear all,

sample xml
==========
<root>
<sec>
First level section.
<sec>
Second level section
<sec>
Third level section.
<sec>
Forth level section
</sec>
</sec>
</sec>
</sec>
</root>

i need sample xsl for the each <sec> to be view in div with different border color.


Pls. do the needful.

Thanks,
Thava
 
Old August 11th, 2009, 08:58 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

You could match on sec/sec, sec/sec/sec, sec/sec/sec/sec and assign the border color as needed:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  
  <xsl:output method="html" indent="yes"/>
  
  <xsl:param name="bg1" select="'red'"/>
  <xsl:param name="bg2" select="'green'"/>
  <xsl:param name="bg3" select="'blue'"/>
  <xsl:param name="bg4" select="'yellow'"/>
  
  <xsl:template match="sec[not(ancestor::sec)]">
    <div style="border: 1px solid {$bg1};">
      <xsl:apply-templates/>
    </div>
  </xsl:template>
  
  <xsl:template match="sec/sec">
    <div style="border: 1px solid {$bg2};">
      <xsl:apply-templates/>
    </div>
  </xsl:template>

  <xsl:template match="sec/sec/sec">
    <div style="border: 1px solid {$bg3};">
      <xsl:apply-templates/>
    </div>
  </xsl:template>

  <xsl:template match="sec/sec/sec/sec">
    <div style="border: 1px solid {$bg4};">
      <xsl:apply-templates/>
    </div>
  </xsl:template>
  
</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old August 11th, 2009, 09:06 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Or you could parameterize it, something like this:

Code:
<xsl:template match="sec">
  <xsl:variable name="depth" select="count(ancestor::sec)+1">
  <div class="div{$depth}">
      <xsl:apply-templates/>
  </div>
</xsl:template>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old August 11th, 2009, 09:18 AM
Authorized User
 
Join Date: Mar 2009
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Martin Honnen View Post
You could match on sec/sec, sec/sec/sec, sec/sec/sec/sec and assign the border color as needed:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  
  <xsl:output method="html" indent="yes"/>
  
  <xsl:param name="bg1" select="'red'"/>
  <xsl:param name="bg2" select="'green'"/>
  <xsl:param name="bg3" select="'blue'"/>
  <xsl:param name="bg4" select="'yellow'"/>
  
  <xsl:template match="sec[not(ancestor::sec)]">
    <div style="border: 1px solid {$bg1};">
      <xsl:apply-templates/>
    </div>
  </xsl:template>
  
  <xsl:template match="sec/sec">
    <div style="border: 1px solid {$bg2};">
      <xsl:apply-templates/>
    </div>
  </xsl:template>

  <xsl:template match="sec/sec/sec">
    <div style="border: 1px solid {$bg3};">
      <xsl:apply-templates/>
    </div>
  </xsl:template>

  <xsl:template match="sec/sec/sec/sec">
    <div style="border: 1px solid {$bg4};">
      <xsl:apply-templates/>
    </div>
  </xsl:template>
  
</xsl:stylesheet>

its working fine thanks a lot.....


Thanks,
Thava





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:function pass param to attribute of xsl:instruction bonekrusher XSLT 4 March 31st, 2009 09:06 AM
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
Pass link values as xsl:parameter to php5 then xsl pauljr8 XSLT 1 July 2nd, 2007 10:32 PM
differnce between xsl:apply-templates and xsl:call chandu.mca007 XSLT 2 June 12th, 2007 04:12 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





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