Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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>
Reply With Quote
  #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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:03 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.