Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access variable in CDATA from XSLT?

Tags:

cdata

xslt

I am using XSLT Transformation and need to put some data in CDATA section and that value is present in a variable.

Query: How to access variable in CDATA ? Sample Given Below:

<xsl:attribute name ="attributeName">
<![CDATA[ 
  I need to access some variable here like
   *<xsl:value-of select ="$AnyVarible"/>* 
 ]]>
</xsl:attribute>

How can I use varibale in CDATA ? Note: I can not use --> &lt;![CDATA[<xsl:value-of select ="$AnyVarible"/>]]&gt; Thanks in advance.

like image 900
Amit Avatar asked Feb 15 '10 10:02

Amit


People also ask

How do I assign a value to a variable in XSLT?

XSLT <xsl:variable> Tip: You can add a value to a variable by the content of the <xsl:variable> element OR by the select attribute!

What is CDATA in XSL?

The term CDATA, meaning character data, is used for distinct, but related, purposes in the markup languages SGML and XML. The term indicates that a certain portion of the document is general character data, rather than non-character data or character data with a more specific, limited structure.

Can we reassign a value to variable in XSLT?

You cannot - 'variables' in XSLT are actually more like constants in other languages, they cannot change value. Save this answer.


2 Answers

I got the solution for this...FYI for everyone...

<xsl:text
disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
<xsl:value-of select ="$AnyVarible"/>
<xsl:text
disable-output-escaping="yes">]]&gt;</xsl:text>
like image 175
Amit Avatar answered Oct 04 '22 23:10

Amit


CDATA is just text like any other element contents...

But using the xsl:output element you should be able to specify which elements are to be written as CDATA with the cdata-section-elements attribute.

EDIT:

Now that there is a valid sample, I guess you mean this:

<xsl:attribute name ="attributeName">
<![CDATA[ 
   I need to access some variable here like
   *]]><xsl:value-of select ="$AnyVarible"/><![CDATA[* 
]]>
</xsl:attribute>
like image 28
Lucero Avatar answered Oct 05 '22 01:10

Lucero