Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jamie 35 posts 87 karma points
    Jul 13, 2011 @ 11:10
    Jamie
    0

    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('&lt;![CDATA[x',image,']]&gt;')" 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('&lt;![CDATA[x',$imageurl,']]&gt;')" 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?

    
    
                    
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 13, 2011 @ 12:26
    Jan Skovgaard
    1

    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

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jul 13, 2011 @ 13:20
    Chriztian Steinmeier
    1

    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:

    <xsl:variable name="imageurl" select="'/assets/test.jpg'" />

    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. 

    /Chriztian

  • Jamie 35 posts 87 karma points
    Sep 19, 2011 @ 11:15
    Jamie
    0

    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.] 

Please Sign in or register to post replies

Write your reply to:

Draft