The rest of my code is referencing things like $currentTabXml/@nodeTypeAlias, which works fine using the above.
Now instead I'd like to set the variable conditionally. For simplicity I've removed the choose statements and tried to reproduce the equivalent to the above line:
But this gives me parse errors in runtime. I've tried all kinds of combinations, value-of, wrapping GetXmlNodeById in msxml:node-set, etc. Any ideas on what I'm missing?
Not sure why you would want to do that Tom, you are already getting the XML back in the right format using your first example?
But I guess you are not converting it to a node-set at the right time. You need to build up your XML first then once finished and you want to use it then convert it into a node-set. I tend to do stuff like this:
<!-- Build up your XML in a temp variable -->
<xsl:variable name="temp_books">
<books>
<xsl:copy-of select="//books/book" />
</book>
</xsl:varable>
<!-- Convert your temp variable to a usable node-set, this way you only need to do it once -->
<xsl:variable name="books" select="msxml:node-set( $temp_books )" />
Thanks for the replies - it helped me figure it out.
The issue was actually due to my lack of xpath knowledge. When changing from my initial code to the conditional with copy-of etc, I found I had to add an extra "/node" after the variable. IE $currentTabXml/@nodeTypeAlias became $currentTabXml/node/@nodeTypeAlias. I added this to a second variable to avoid having to change a bunch of code as Peter suggested.
Thanks again, this has been bugging me for a while on other projects
Conditionally assign XML to a variable - parse errors
Hi all,
I'm having some trouble figuring out how to conditionally assign XML to a variable in XSLT.
Here's what I started with:
The rest of my code is referencing things like $currentTabXml/@nodeTypeAlias, which works fine using the above.
Now instead I'd like to set the variable conditionally. For simplicity I've removed the choose statements and tried to reproduce the equivalent to the above line:
But this gives me parse errors in runtime. I've tried all kinds of combinations, value-of, wrapping GetXmlNodeById in msxml:node-set, etc. Any ideas on what I'm missing?
Thanks,
Tom
Tom,
Paste the whole code for the conditional set of the variable it will give clearer picture.
Regards
Ismail
Not sure why you would want to do that Tom, you are already getting the XML back in the right format using your first example?
But I guess you are not converting it to a node-set at the right time. You need to build up your XML first then once finished and you want to use it then convert it into a node-set. I tend to do stuff like this:
Hope that sheds some light?
Thanks for the replies - it helped me figure it out.
The issue was actually due to my lack of xpath knowledge. When changing from my initial code to the conditional with copy-of etc, I found I had to add an extra "/node" after the variable. IE $currentTabXml/@nodeTypeAlias became $currentTabXml/node/@nodeTypeAlias. I added this to a second variable to avoid having to change a bunch of code as Peter suggested.
Thanks again, this has been bugging me for a while on other projects
is working on a reply...