Re: [xsl] Passing xml nodes to a function

Subject: Re: [xsl] Passing xml nodes to a function
From: "Robin Harvey" <harvey.robin@xxxxxxxxx>
Date: Wed, 9 Aug 2006 16:17:32 +0100

If all you want is the text of the target nodeset, why not just all
apply-templates and select the node you're interested in.  I think
that the default templates will then output all of the text nodes and
strip anything else.
If you need something more complex, look in to using an identity
template.  This simply maps the input document to the output, and
allows you to do selective filtering.  the basic identity template
looks something like this:

<xsl:template match="node()|@*">
   <xsl:apply-templates select="node()|@*"/>

You can filter on specific elements or attributes by adding in another
template *above* the default identity template to operate on the nodes
you're interested in (this must be above the default ID, to give it a
greater precedance).  Say you wanted to catch all elements called

<xsl:template match="*[name() = 'fark']>
 <xsl:value-of select="text()"/>

<!-- default ID comes next -->

The example above will catch all 'fark' elements and output the text
nodes they contain, missing out the elements themselves


On 8/9/06, Bansal, Rabinder <RBansal@xxxxxxxxxxxxxxx> wrote:

I have a requirement to pass a parent node to a recursive function and then to recurse through all the child nodes. I am a novice at xsl and so this is proving to be quite taxing.

Here is the code:

   This is where I call the function:-

<xsl:call-template name="getChildDetails">

                    <xsl:with-param name="children" select=".//response/*/response/*"/>

and this is the actual function where I want to test for the presence of children, output the node name and then call the method again until all nodes are printed :-

<xsl:template name="getChildDetails"> <xsl:param name="children"/>

<xsl:if test="count(children::*) > 0">

             <td><span class="text"><xsl:value-of select="name()"/></span></td>
             <xsl:call-template name="getChildDetails">
                 <xsl:with-param name="children" select="child::*"/>


Here is an example of an XML:

<teleNumbers> <telList> <numbers> <teleType>H</teleType> <teleNumber>0145454545</teleNumber> </numbers> </telList> </teleNumbers>

The output I expect from this xsl once it has run through the recursive function is as follows:-

                teleType        H
                teleNumber      0145454545

I look forward to your help.


********************** N O T I C E *********************************

This message and any attachments is intended only for the individual or company to which it is addressed and may contain
information which is privileged, confidential or prohibited from disclosure or unauthorised use. If the recipient of this
transmission is not the intended recipient, or the employee or agent responsible for delivering such materials to the
intended recipient, you are hereby notified that any use, any form of reproduction, dissemination, copying, disclosure,
modification, distribution and/or publication of this e-mail message or its attachments other than by it's intended
recipient is strictly prohibited by the sender. If you have received it in error, please notify us immediately by
telephone on the number above and destroy the message and all copies in your possession.

International Financial Data Services (UK) Ltd is authorised and regulated by the Financial Services Authority.

This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses.


Current Thread