Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old May 4th, 2005, 01:04 PM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL Parameter xsl:param

I am new to XSLT, please help me.
Ex sample.xml
-------------
<summary>
 <id>10001</id>
 <date>
   <time>12:00 AM</time>
   <dateTime>10/8/04 12:00 AM</dateTime>
   <month>10</month>
   <day>8</day>
   <year>2004</year>
 </date>
 <countryCode>US</countryCode>
<summary>

I want to create a template that takes date node and country code and display the value of different formats for different country codes.

Ex:sample.xsl
-------------
<xsl:param name="date"/>
<xsl:param name="countryCode"/>
<xsl:choose>
    <xsl:when test="$countryCode = 'US'">
        <xsl:value-of select="$date/month"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="$date/day"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="$date/year"/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="$date/time"/>
    </xsl:when>
    <xsl:when test="$countryCode = 'POL'">
        <xsl:value-of select="$date/day"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="$date/month"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="$date/year"/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="$date/time"/>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="$date/year"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="$date/month"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="$date/day"/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="$date/time"/>
    </xsl:otherwise>
</xsl:choose>
  #2 (permalink)  
Old May 6th, 2005, 03:15 AM
Authorized User
 
Join Date: Jul 2004
Location: Oxford, , United Kingdom.
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your code looks fine - Are you asking how to call it?

If so,

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:call-template name="showDate">
            <xsl:with-param name="date" select="summary/date"/>
            <xsl:with-param name="countryCode" select="summary/countryCode"/>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="showDate">
        <xsl:param name="date"/>
        <xsl:param name="countryCode"/>
        <xsl:choose>
            <xsl:when test="$countryCode = 'US'">
                <xsl:value-of select="concat($date/month, '/', $date/day, '/', $date/year, ' ', $date/time)"/>
            </xsl:when>
            <xsl:when test="$countryCode = 'POL'">
                <xsl:value-of select="concat($date/day, '/', $date/month, '/', $date/year, ' ', $date/time)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="concat($date/year, '/', $date/month, '/', $date/day, ' ', $date/time)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>


</xsl:stylesheet>

Regards
Bryan



Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
Pass xsl:param to xsl:if bonekrusher XSLT 5 September 6th, 2007 04:37 PM
Pass link values as xsl:parameter to php5 then xsl pauljr8 XSLT 1 July 2nd, 2007 10:32 PM
xsl:variable holding name of an xsl:param perissos XSLT 0 December 5th, 2006 07:09 AM
The difference between xsl:variable and xsl:param NEO1976 XML 2 July 24th, 2006 06:05 AM





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