[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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 12:36:24 +0000

On 06/11/2013 12:24, henry human wrote:
There is still one issue,
cause the root elment is dnamiccaly , sometimes I need to get the root name:
<xsl:variable name="Root">
<xsl:value-of select="/node()[1]/name()"/>

Root is a bad name (since in xpath the root is / which is the parent of the element that you want) you want /*[1] (It is much better to use * rather than node() here otherwise a comment or processing instruction will break your code.)

Don't use a variable with content as that generates a temporary tree, you just want a string so use

<xsl:variable name="Root" select="/*[1]/name()"/>

I try it in output
  <xsl:value-of select="$Root"/>

As Result
I get the right root name, RootElement but the namespace in the output coccures too:
     <tesTag xmlns:ns1=http://xmlns.oracle.com/applicaation/mu/v1"/>RootElement</tesTag>

The namespace is not in the XML,. it is actually defined in the XSL stylesheet header!!

That is the standard behaviour for literal result elements, the declared namespace is in scope. You can use


on your xsl:stylesheet element to stop this.


________________________________________________________________________ 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