Re: How to convert string to Node in xslt
ajay bhadauria <[email protected]> Tue, 22 Nov 2011 06:24:32 -0800 (PST)
| Newsgroups | gmane.text.xml.xalan.java.user |
|---|---|
| Message-ID | <[email protected]> |
Mukul,
Thanks a lot !
But it did not work.
<xsl:element name="{$v1}">
<xsl:copy-of select="*/Request/RequestHeader"/>
</xsl:element>
----> it says that it requires QNAME. I tried to use "($v1)" , It was simply ignoring.
2)
xsl:copy-of select="*[local-name() = $v1]/Request/RequestHeader"/>
This was also ignoring siliently.
I found something nodeset on Apache website which converts string to nodeset but due
some reason that also does not work.
xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="xalan">
<xsl:copy-of select="xalan:nodeset($v1)/Request/RequestHeader"/>
I do not know why this does not. It is also simply ignoring. I am using xalan-2.7.1
Regards
Ajay
--- On Sun, 11/20/11, Mukul Gandhi <[email protected]> wrote:
From: Mukul Gandhi <[email protected]>
Subject: Re: How to convert string to Node in xslt
To: "ajay bhadauria" <[email protected]>
Cc: [email protected]
Date: Sunday, November 20, 2011, 10:33 AM
Hi Ajay,
Let's assume your variable "v1" would finally have a value in it (based on some selection logic that you want to write, which essentially extracts data from your input XML document), as below,
<xsl:variable name="v1" select="'SendRequest'"/> <!-- or can have value 'ExchangeRequest' -->
(I've directly written the value for this variable, but in your case the value would be computed as you wrote)
You now essentially want to copy a node to output XSLT tree as below,
<xsl:copy-of select="$v1/Request/RequestHeader"/>
Of course this would not work, since 'v1' here is not a node and is a string value.
But I think, the following would probably work,
<xsl:copy-of select="*[local-name() = $v1]/Request/RequestHeader"/>
Or perhaps something like below would also work (which is closer to what you're asking i.e text to a node),
<xsl:element name="{$v1}">
<xsl:copy-of select="*/Request/RequestHeader"/>
</xsl:element>
Does any of above approaches suites you better?
On Sat, Nov 19, 2011 at 10:12 PM, ajay bhadauria <[email protected]> wrote:
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
--
Regards,
Mukul Gandhi