Hi Mukul,

Thanks a lot for reply.

The solution you gave will work. But in my xml file, the root element of 
document could  SendRequest or ExchangeRequest. So I was thinking that I could 
define a variable and based upon the value of  this variable ( SendRequest or 
ExchangeRequest) I can copy all the elements.

Sorry about that I have not mentioned in my last query.

So , if there anything is anything in the XSL which I can use it and convert 
text to node.


Regards
Ajay 

--- On Sat, 11/19/11, Mukul Gandhi <gandhi.mu...@gmail.com> wrote:

From: Mukul Gandhi <gandhi.mu...@gmail.com>
Subject: Re: How to convert string to Node in xslt
To: "ajay bhadauria" <abhadau...@yahoo.com>
Cc: xalan-j-users@xml.apache.org
Date: Saturday, November 19, 2011, 3:15 PM

Hi Ajay,
    From your problem description, it seems you effectively need an XSLT 
stylesheet like following,

<xsl:stylesheet version="1.0" xmlns:SwInt="some-namespace-ref">

     <xsl:output method="xml" encoding="UTF-8" indent="yes"/>


 
     <xsl:template match="/">
         <SwInt:RequestDescriptor>
            <xsl:copy-of select="*/Request/RequestHeader"/>
        </SwInt:RequestDescriptor>


     </xsl:template>

</xsl:stylesheet>

(not tested)

and it seems, you wouldn't need a text to node facility.

Please feel free to report, if above solution doesn't work, and we could 
possible suggest something different.



On Sat, Nov 19, 2011 at 3:27 AM, ajay bhadauria <abhadau...@yahoo.com> wrote:


Hi ,
 
I have a variable in my xslt and based on the value of the variable, I need to 
select the xpath but the variable is not getting translated to node since it is 
text. So how I can convert text(string ) to node. Is there any alternate way of 
doing it ?


 
Regards
Ajay
 
My XSLT is 
 
 <xsl:stylesheet version="1.0" >
 <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
 <xsl:template match="/">
  <xsl:variable name="v1">


   <xsl:for-each select="/SendRequest|/ExchangeRequest">
    <xsl:choose>
     <xsl:when test="(local-name()='SendRequest')">
      <xsl:value-of select="SendRequest"/>


     </xsl:when>
      <xsl:when test="(local-name()='ExchangeRequest')">
      <xsl:value-of
 select="ExchangeRequest"/>
     </xsl:when>
    </xsl:choose>
   </xsl:for-each>
  </xsl:variable>
  <SwInt:RequestDescriptor>
   <xsl:copy-of select="$v1/Request/RequestHeader"/>


  </SwInt:RequestDescriptor>
 </xsl:template>
</xsl:stylesheet>
 
--------------------------
XML is 
<SendRequest >
 <Request>
  <RequestHeader>
   <Requestor>xyz</Requestor>
   <Responder>abc</Responder>
   <RequestType>test</RequestType>
  </RequestHeader> 


 </Request>
</SendRequest>




-- 
Regards,
Mukul Gandhi

Reply via email to