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 22nd, 2009, 09:38 AM
Authorized User
 
Join Date: May 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing a node name to generic template

Let me explain the scenario.

I have written a generic template which copies all the element from the source tree . I want to add a logic to filter a node in the output tree which is passed as an argument .

Here's the xsl code : -


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="exclude-node" select="'amount'"></xsl:param>
<xsl:template match="*">
<xsl:choose>
<xsl:when test="local-name()=$exclude-node">
<xsl:call-template name="AnotherTemplate"></xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:copy-of select="@*"></xsl:copy-of>
<xsl:apply-templates></xsl:apply-templates>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="AnotherTemplate">
<xsl:param name="inputData"></xsl:param>
</xsl:template>
</xsl:stylesheet>

input xml :

<?xml version="1.0" encoding="UTF-8"?>
<departments>
<employee1>
<salary>
<amount>30</amount>
</salary>
</employee1>
<employee2>
<amount>
<amount>40</amount>
<currency>USD</currency>
</amount>
</employee2>
</departments>

Problem -

I can use the below statment to see if the context node is same as the argument .
<xsl:when test="local-name()=$exclude-node">

In the xml , <amount> contains a child node "amount" , i have to call Another Template for node <amount> which does not contains the any child node amount.

Since the node name is treated as a string , iam not able to write any xpath expression.

Hope iam clear with the explantion.

Let me know if this is feasible without using any dynamic xsl.

Thanks,
Arun
 
Old July 22nd, 2009, 11:16 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I think you want to check test="local-name() = $exclude-node and not(*[local-name() = $exclude-node])". That way you check that there is no child element with the local name being $exclude-node.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old July 23rd, 2009, 08:21 AM
Authorized User
 
Join Date: May 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Martin. this solution works for me





Similar Threads
Thread Thread Starter Forum Replies Last Post
Create generic XSL Template to create table Venkatachalapathy XSLT 5 March 11th, 2008 07:49 AM
Passing Node as a Param from javascript to XSL pnviv XSLT 4 November 15th, 2007 05:57 AM
Creating a template to generate a node set Chamkaur XSLT 1 July 27th, 2007 02:51 AM
Generic templates and only one node() Clyne XSLT 4 January 5th, 2007 12:47 AM
Counting node-set children in template rufustfirefly XSLT 2 May 3rd, 2004 08:48 AM





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