xsl-list
[Top] [All Lists]

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

2013-11-06 06:36:38
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()"/>
  </xsl:variable>


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
         <tesTag>
  <xsl:value-of select="$Root"/>
          </tesTag>

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

exclude-result-prefixes

on your xsl:stylesheet element to stop this.

David


________________________________________________________________________
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. ________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--