p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   XSL Parameter xsl:param (http://p2p.wrox.com/showthread.php?t=28939)

Harinath Chikoti May 4th, 2005 01:04 PM

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>

barcher May 6th, 2005 03:15 AM

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



All times are GMT -4. The time now is 02:40 PM.

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