I'm needin umbraco to build an XML formatted document for a flash movie that is loading in variables via a fixed url (as in I do not have access to the source to chnage it). I have most of it work however the only way I could get umbraco to output <![CDATA[ ]]> was to use concatination.
This works fine for a value comming from the 'doctype' proprties
The reason your $imageurl doesn't work, is that where you think you're specifying a string, you're actually specifying an XPath, so it's trying to set the variable to the value of the <test.jpg> element inside the root element <assets> ! :-)
You just need to wrap it in single quotes to specify a string:
To output CDATA you really should be using the cdata-section-elements attribute on the xsl:output element, e.g:
<xsl:output cdata-section-elements="img" />
Which will make sure that everytime an <img> element is generated by the XSLT processor, it'll wrap its contents in a CDATA Section and make sure that its contents is escaped correctly.
Christian though showed me the better way to do this .. which what my secret hope in asking the question as I could find nothign on CDATA and umbraco XSLT at the time.
[sorry this wasn't marked as such at the time thoguht I had give a more robust thank you but it appears not to have saved / submitted.]
Using variable in a concatenation in XSLT
I'm needin umbraco to build an XML formatted document for a flash movie that is loading in variables via a fixed url (as in I do not have access to the source to chnage it). I have most of it work however the only way I could get umbraco to output <![CDATA[ ]]> was to use concatination.
This works fine for a value comming from the 'doctype' proprties
<img><xsl:value-of select="concat('<![CDATA[x',image,']]>')" disable-output-escaping="yes"/></img>
outputs <img><![CDATA[0]]></img> the input in the doctype is a true/false.
But if I try and define a variable it does not work .
<xsl:variable name="imageurl" select="/assets/test.jpg"/>
<img><xsl:value-of select="concat('<![CDATA[x',$imageurl,']]>')" disable-output-escaping="yes"/></img>
outputs <img><![CDATA[]]></img> so no data.
I can't seem to figure out why this is.. any ideas? Is thier somehtign special I need to do when including a variable in a concatinated string?
Hi Jamie
Try doing this instead
<img><xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text> <xsl:value-of select="$imageurl" /> <xsl:text disable-output-escaping="yes">]]></xsl:text></img>
Hope this helps.
/Jan
Hi Jamie,
The reason your $imageurl doesn't work, is that where you think you're specifying a string, you're actually specifying an XPath, so it's trying to set the variable to the value of the <test.jpg> element inside the root element <assets> ! :-)
You just need to wrap it in single quotes to specify a string:
To output CDATA you really should be using the cdata-section-elements attribute on the xsl:output element, e.g:
Which will make sure that everytime an <img> element is generated by the XSLT processor, it'll wrap its contents in a CDATA Section and make sure that its contents is escaped correctly.
/Chriztian
Jan solved my immidate problem.
Christian though showed me the better way to do this .. which what my secret hope in asking the question as I could find nothign on CDATA and umbraco XSLT at the time.
[sorry this wasn't marked as such at the time thoguht I had give a more robust thank you but it appears not to have saved / submitted.]
is working on a reply...