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 July 21st, 2006, 07:47 AM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to avoid variable from getting in the output..

Hi
  I am a beginner in XSL. I am trying with following :

XML:
<ScemaVariables>
   <contacts>Test Contact1</contacts>
   </ScemaVariables>

XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output method="xml"/>
    <xsl:variable name="xxx">xxxconstantvalue</xsl:variable>
    <xsl:variable name="contacts1">
        <xsl:value-of select="//contacts"/>
    </xsl:variable>
    <xsl:template match="/">
        <xsl:apply-templates/>
    Value of Contacts is : <xsl:value-of select="$contacts1"/>
    Value of xxx is : <xsl:value-of select="$xxx"/>
    </xsl:template>
</xsl:stylesheet>

Expected Output:
 Value of Contacts is : Test Contact1
 Value of xxx is : xxxconstantvalue

Actual Output:

   Test Contact1

        Value of Contacts is : Test Contact1
        Value of xxx is : xxxconstantvalue


I dont know why the Test Contact1 is getting printed while assigning the variable. Its messing up my output XML. Any way to avoid getting that in the output ?

Thanks a lot

Ahmed


 
Old July 21st, 2006, 09:19 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You called xsl:apply-templates. That processes the children of the context node. There's no explicit template that matches the children, the default template fires. This cascades its way all down the tree. The default template for text nodes is to copy the text to the output. If you don't want to process the child nodes, don't call apply-templates.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Return output variable to VB from SQL stored proc busterbunny BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 March 27th, 2006 10:24 PM
how to avoid logon justin_min Crystal Reports 0 November 30th, 2004 02:05 PM
Trying to avoid duplicacy aspadda Excel VBA 0 April 23rd, 2004 12:59 PM
How do I Avoid a ROLLBACK when... wmhhodson SQL Server 2000 1 October 31st, 2003 01:07 AM





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