Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need < & > sign after applying XSLT

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a requirement where I need following line in an XML file (this file is generated after applying XSLT):



This number is generated dynamically (with the help of for loop).

Now if I write following line in my XSLT:

*![CDATA[<xsl:value-of select='position()'/>]]*

Where first star is: and, lt and colon.
And last star is: and, gt and colon.

I get following in my output XML file:

*![CDATA[2]]*

Which doesn't solve my purpose.

I can't write like this in my XSLT:




Please help. How do I get this?

Thanks.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This software was converting and, gt and colon to > so I had to mention it like this...


 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you don't really need that, you know. The CDATA section is really just a convenience for people whose serializers can't handle escaping properly and for people typing XML into a text editor. You can just as well output this:

and all compliant XML parsers will treat that exactly the same as they would treat

However it's possible to have your XSLT output as CDATA every text child of elements with specific names. Look up the "cdata-section-elements" attribute of the xsl:output element.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ankur rathi wrote:This software was converting and, gt and colon to < so I had to mention it like this...


You can escape those characters in the forum exactly as you would escape them in an XML document.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Well, you don't really need that, you know. The CDATA section is really just a convenience for people whose serializers can't handle escaping properly and for people typing XML into a text editor. You can just as well output this:

and all compliant XML parsers will treat that exactly the same as they would treat

However it's possible to have your XSLT output as CDATA every text child of elements with specific names. Look up the "cdata-section-elements" attribute of the xsl:output element.


Thanks Paul.

I have added cdata-section-elements="namelist" in my xsl:output tag but it doesn't make any difference.
Do I need to change something in xsl:value-of tag?

Thanks.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It worked for me when I just tried it. But I have no idea what "namelist" is so I can't suggest anything except providing information about your question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic