[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: henry human <henry_human@xxxxxxxx>
Date: Wed, 6 Nov 2013 15:49:26 +0000 (GMT)

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
/* or this notation <xsl:for-each
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"> 
<xsl:value-of select="ChildElment1/ChildElement2/getVersion"></Version>
The output is:
but following works
<xsl:for-each select="RootElement">  


David Carlisle <davidc@xxxxxxxxx>
schrieb am 13:36 Mittwoch, 6.November 2013:
On 06/11/2013 12:24, henry human
> 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, 
just want a string so use

<xsl:variable name="Root" select="/*[1]/name()"/>
> I try it in output
>          <tesTag>
>   <xsl:value-of select="$Root"/>
> As Result
> I get the right root name, RootElement but
the namespace in the output coccures too:
>      <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.

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