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 October 27th, 2007, 06:16 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

<xsl:variable name="LastName">
   <xsl:value-of select="XYZ"/>
</xsl:variable>

The above code sets the variable $LastName to the value of the element called <XYZ>. That's probably not what you are trying to do. If you want it to be the string "XYZ" then enclose it in single quotes, e.g. select="'XYZ'".

Its still not clear what your input XML looks like.

/- Sam Judson : Wrox Technical Editor -/
 
Old October 27th, 2007, 07:19 AM
Authorized User
 
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default


XML (Input File) :

<Interfaces>
    <DATA>
        <Status>ValidCustomer</Status>
        <Name>ABC</Name>
        <LastName>XYZ</LastName>
        <MessageName>FeeEnquiryRQ</MessageName>
    </DATA>
</Interfaces>



********************************

XSL file :

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="DATA">
    <xsl:variable name="Append">
        <xsl:value-of select="'~'"/>
         </xsl:variable>
        <xsl:variable name="Status">
        <xsl:value-of select="Status"/>
        </xsl:variable>
        <xsl:variable name="Name">
        <xsl:value-of select="Name"/>
    </xsl:variable>
    <xsl:variable name="LastName">
        <xsl:value-of select="LastName"/>
    </xsl:variable>

    <xsl:element name="INFORMATION">
        <xsl:choose>
            <xsl:when test="[MessageName='Verify']">
                <xsl:call-template name="Inquiry"></xsl:call-template>
            </xsl:when>
            <xsl:when test="[MessageName='Verify1']">
               <xsl:call-template name="Inquiry1"></xsl:call-template>
            </xsl:when>
        </xsl:choose>
    </xsl:element>
  </xsl:template>
    <xsl:template name="Inquiry">
        <xsl:value-of select="$Status"/>
        <xsl:value-of select="$Append"/>
        <xsl:value-of select="$Name"/>
        <xsl:value-of select="$Append"/>
        <xsl:value-of select="$LastName"/>
    </xsl:template>
    <xsl:template name="Inquiry1">
        <xsl:value-of select="$Status"/>
        <xsl:value-of select="$Append"/>
        <xsl:value-of select="$Name"/>
        <xsl:value-of select="$Append"/>
        <xsl:value-of select="$LastName"/>
    </xsl:template>

    <xsl:template match="text()"/>
</xsl:stylesheet>


***************************
Required OutPut [but i m not getting this]


    <INFORMATION>ValidCustomer~ABC~XYZ</INFORMATION>


 
Old October 27th, 2007, 11:03 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Variables declared within one template aren't accessible in another template - they are like local variables declared within a function or method in C or Java. If you want to pass values from one template to another, you need to pass them as parameters. You pass the parameter using <xsl:with-param> in the calling template, with a matching xsl:param in the called template to declare the parameter and receive the value.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 30th, 2007, 07:20 AM
Authorized User
 
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

:)

 
Old October 31st, 2007, 02:37 AM
Authorized User
 
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

:)

 Hi Michael Kay

  Thanks it is Working now .:)

 
Old October 31st, 2007, 02:39 AM
Authorized User
 
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 Hi Michael Kay
 is there any way to declare variable globally so that it can access by all the template in same XSL.

 
Old October 31st, 2007, 04:16 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Global variables are just variables declared at the top level. In your example $Append and $Status ARE global variables.

/- Sam Judson : Wrox Technical Editor -/
 
Old November 2nd, 2007, 12:08 PM
Authorized User
 
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi samjudson,

So I can us $Append and $Status without using <xsl:with-param> in the templet. below right

 
Old November 3rd, 2007, 05:40 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Try it and see.

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Access Variable outside for-each dishant XSLT 4 September 25th, 2008 03:53 AM
access the local variable value out side ravi_sri24 XSLT 17 May 7th, 2008 08:43 AM
Global Access to a Variable ? navdeep C# 15 July 19th, 2007 08:44 PM
Populate a Variable From Access Table sirmilt Access 5 March 21st, 2006 01:34 AM
Passing a Variable to a SubForm in Access ritag Access 1 September 29th, 2004 03:53 PM





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