Re: [xsl] find the name of the child after root

Subject: Re: [xsl] find the name of the child after root
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 06 Nov 2013 16:04:43 +0000
On 06/11/2013 15:49, henry human wrote:
That works with the exclude-result-prefixes avoiding the namespace, thanks,  but now I face following:
Originally I wanted o use the name of the root or the next child to loop over in a for-each as bellow

<xsl:for-each select="/node()[1]/name()">
/* or this notation <xsl:for-each select="/*[1]/local-name()"/>*/

/*[1]/local-name() is a sequence of one string, so why would you want to for-each over it? It is legal and makes . equal to that string but
apart from using <xsl:value-of select="."/> to output the string there is not much useful stuff you can do inside the loop.

which does not work. I get no elments from the xml tree because the xpath does not works . I cant work with the XML for example say:
     <xsl:variable name="Root">

<xsl:value-of select="/*[1]/local-name()"/>

<xsl:for-each select="$Root">

Again that for-each is iterating over a sequence of length 1, so does nothing useful. In this case the item is a root node / with child a single text node with value the name of the top level element in the original document.

<Version> <xsl:value-of select="ChildElment1/ChildElement2/getVersion"></Version> </xsl:for-each> The output is: <Version/>

well yes because you are iterating over a sequence of nodes (or sequence of strings) that are not in the original document, so in the string case it's an error to try to select ChildElment1 as strings don't have child nodes and in the $Root case it is not an error it just selects nothing as $Root has no child elements.

but following works <xsl:for-each select="RootElement"> <Version><xsl:value-of select="ChildElement1/ChildElement2/getVersion"></Version> </xsl:for-each> Output: <Version>1.26</Version>

That is selecting nodes in your input document.



________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. ________________________________________________________________________

Current Thread