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 April 26th, 2005, 03:19 AM
Authorized User
 
Join Date: Apr 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Functions, select case and the like...

Hi Gents

I'm kinda new to XSLT and have a few (probably easy) questions...

Background: Im building a vb.net app that builds classes according to a template (xslt) and in doing so needs some tricky tweaking.

Question:

Can you in XSLT create your own functions? Ie. send a variable to an xslt function that returns a result after some computation...

Basically a similar piece of code will occur throughout and the last thing I want to do is code it again and again in various places...

Thanks



 
Old April 26th, 2005, 04:33 AM
Authorized User
 
Join Date: Apr 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes!

1. For "Functions" in vb.net you can use

The below xsl statements are recursive templates just like finding a factorial of a given number in VB/VB.net

<xsl:call-template name="Print">
      <xsl:with-param name="i" select="'10'"/>


</xsl:call-template

<xsl:template name="Print">
 <xsl:param name="i"/>
  <xsl:value-of select="$i"/><br/>
<xsl:if test="$i &lt; 10">

     <xsl:call-template name="Print">
          <xsl:with-param name="i" select="$i"/>

      </xsl:call-template>
</xsl:if>
</xsl:template>

2. for "select case" statements

   <xsl:choose>
     <xsl:when test="$i=1">
         <xsl:value-of select="you have entered number 1"/>
     </xsl:when>


     <xsl:when test="$i=2">
         <xsl:value-of select="you have entered number 3"/>
    </xsl:when>

     <xsl:when test="$i=3">
         <xsl:value-of select="you have entered number 3"/>
     </xsl:when>

     <xsl:otherwise>
         <xsl:value-of select="you have entered number 0 or greater then 3"/>


  </xsl:otherwise>



    </xsl:choose>


 
Old April 26th, 2005, 04:49 AM
Authorized User
 
Join Date: Apr 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Raman

That is brilliant thanks so much. Should meet my needs perfectly. I presume that the <xsl:template name="Print"> etc... will just sit within the template/file that I am working in? And then when I call it the response would go directly into where i called it from? So somthing like...

some code some code some code bla bla bla some code some code some code bla bla bla some code some code some code bla bla bla some code some code some
<xsl:call-template name="Print">
      <xsl:with-param name="i" select="'10'"/>
</xsl:call-template>
code bla bla bla some code some code some code bla bla bla some code some code some code bla bla bla some code some code some code bla bla bla some code some code some code bla bla bla

Would become...


some code some code some code bla bla bla some code some code some code bla bla bla some code some code some code bla bla bla some code some code some
<result>
code bla bla bla some code some code some code bla bla bla some code some code some code bla bla bla some code some code some code bla bla bla some code some code some code bla bla bla

? Make sence? Or would I have to use another command to use the result of the function?

Thanks again :P

 
Old April 26th, 2005, 05:02 AM
Authorized User
 
Join Date: Apr 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You does not what is XML concept. Learn the XML and XSLT concepts






Similar Threads
Thread Thread Starter Forum Replies Last Post
select case bacster Classic ASP Basics 2 May 1st, 2006 06:31 PM
Using IS in Select Case mega Pro VB 6 4 August 22nd, 2005 08:40 AM
Select Case junaidraja30 Access VBA 1 February 5th, 2005 08:30 PM
Select Case morpheus VB How-To 1 August 13th, 2003 09:14 AM
Select Case andy24 Classic ASP Databases 5 July 25th, 2003 07:52 AM





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