It's not that XSLT is a bad language, (quite the opposite), it more that there is a misunderstanding that it's a declarative language, but its all too often treated (and abused) as a functional/procedural language.
XSLT's power is in transforming XML data-sources, (sounds obvious I know), but when trying to create a string-based XML node-set, I can see how this is frustrating and confusing! Chriztian and Dan's suggestion of creating the XML nodes in a variable, then applying the msxml:node-set function is the best way of achieving this.
I'm curious what you meant about your "5 simple questions" ... what else is troubling you with XSLT? (we're happy to help)
And in this code I used itemElement param to generate integer in different elements, like this:
<item>1<item><item>2<item> or <month>1<month><month>2<month> and etc.
But I can not use <element name="$itemElement"> because XSLT forbidden use variables in names. But why? What is wrong with generation not static XML elements.
XSLT created to generate XML and it can not create flexible XML, only static. Why?
Hi AlexR, I do understand your frustrations. All you want is possible, but there is a learning curve.
You can use a variable with <xsl:element>, like this:
<xsl:element name="{$itemElement}"></xsl:element>
The variable needed to be wrapped in curly brackets.
The XPath as a string has been a constant cause of confusion/frustration to devs on the forum, mostly due to the encoding of quotes (both single and double). If you have an example of what you want to do, I'm sure we can help. I wont promise that it will be pretty code, but it should be achievable!
Take a look at some of the other forum topics on this:
With all this said, if you are happier developing using the .NET APIs, (C#/VB.NET, LINQ, etc), then I'd say go for it! That's the beauty of Umbraco, its flexible to develop with whatever you are most comfortable with, whether that's XSLT, C#, Python, (and soon more). :-)
How to convert string to node set ?
What is wrong with next code?
It is return 0!
Hi AlexR,
Sadly, that's not how the node-set() function works. You'll need an XSLT extension for that...
/Chriztian
- Refer to this comment to see how the node-set() function can be used: http://our.umbraco.org/forum/developers/xslt/9360-xsl-if-array?p=0#comment34272
/Chriztian
What function can be used to convert string to node set?
I see that xslt very, very, very bad language.
I asked about 5 simple questions and got only one answer. All other questions don't have answers.
Hi Alez
xslt can be frustrating (unless you're as fluent as Chriztian!) but this should work for you
Hope this helps,
Dan
Hi AlexR,
It's not that XSLT is a bad language, (quite the opposite), it more that there is a misunderstanding that it's a declarative language, but its all too often treated (and abused) as a functional/procedural language.
XSLT's power is in transforming XML data-sources, (sounds obvious I know), but when trying to create a string-based XML node-set, I can see how this is frustrating and confusing! Chriztian and Dan's suggestion of creating the XML nodes in a variable, then applying the msxml:node-set function is the best way of achieving this.
I'm curious what you meant about your "5 simple questions" ... what else is troubling you with XSLT? (we're happy to help)
Cheers, Lee.
I known that code from dandrayne will work, but I have code that ca not be transfered to code like dandrayne's code.
For example I writes xslt template that generate range sequence of integers.
And in this code I used itemElement param to generate integer in different elements, like this:
<item>1<item><item>2<item> or <month>1<month><month>2<month> and etc.
But I can not use <element name="$itemElement"> because XSLT forbidden use variables in names. But why? What is wrong with generation not static XML elements.
XSLT created to generate XML and it can not create flexible XML, only static. Why?
I tried to use trick to generate elements as text
But I can not use it also. Because XSLT can not convert string to node set. Why it can not convert string to node set? What wrong with this?
I so on, so no, so on...
XSLT bad language. It is not flexible and have many unusual restrictions.
Other big restriction that I can not use variables in xpath expressions. I can not generate xpath as string.
How I can flexible transform XML when XSLT is not flexible, it is static.
You should hard-code all in your code - it is stupid.
So I think that is better to call C# functions that will use LINQ to XML and can generate anything without unusual restrictions.
Hi AlexR, I do understand your frustrations. All you want is possible, but there is a learning curve.
You can use a variable with <xsl:element>, like this:
The variable needed to be wrapped in curly brackets.
The XPath as a string has been a constant cause of confusion/frustration to devs on the forum, mostly due to the encoding of quotes (both single and double). If you have an example of what you want to do, I'm sure we can help. I wont promise that it will be pretty code, but it should be achievable!
Take a look at some of the other forum topics on this:
http://our.umbraco.org/forum/developers/xslt/8496-Dynamic-XPath-query
http://our.umbraco.org/forum/developers/xslt/6400-Has-Anyone-Actually-Got-GetXmlNodeByXPath-Working
With all this said, if you are happier developing using the .NET APIs, (C#/VB.NET, LINQ, etc), then I'd say go for it! That's the beauty of Umbraco, its flexible to develop with whatever you are most comfortable with, whether that's XSLT, C#, Python, (and soon more). :-)
Cheers, Lee.
is working on a reply...