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 <xsl:for-each select="/node()[1]/name()"> /* or this notation <xsl:for-each select="/*[1]/local-name()"/>*/ 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:variable> <xsl:for-each select="$Root"> <Version> <xsl:value-of select="ChildElment1/ChildElement2/getVersion"></Version> </xsl:for-each> The output is: <Version/> 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> brg David Carlisle <davidc@xxxxxxxxx> schrieb am 13:36 Mittwoch, 6.November 2013: 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. ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] find the name of the chi, David Carlisle | Thread | Re: [xsl] find the name of the chi, David Carlisle |
Re: [xsl] JSON-encoding strings in , Michael Kay | Date | Re: [xsl] find the name of the chi, David Carlisle |
Month |