Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 20th, 2009, 08:57 AM
Registered User
 
Join Date: Mar 2009
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default XSLT-escape-sequence

My input xml/xmi file contains special characters like &lt;&gt,space and &quot; .When i am applying XSLT transform on it these as coming as it is or in some different format like &lt->&lt,&gt->&gt and &quote ->&#34.I need those to come as coresponding symbols like <,> or ".
For space i used normalise-space() for the same and it is ok.Give me some solution for other special symbols.
Mailto:[email protected]
Thanks in advance
 
Old March 20th, 2009, 09:11 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Please post a relevant sample of your XML input and show us the stylesheet you use and the output you get and the output you want to get.
Do you use XSLT 1.0 or 2.0?
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old March 20th, 2009, 09:12 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you want to output "<", then this is probably because you are generating markup rather than text. Remember that XSLT produces a result tree, which is then serialized. If you want markup in the serialized output, you need to generate nodes in the result tree, which you do using instructions such as xsl:element or xsl:comment. Don't try to produce lexical XML markup directly from your XSLT code, that's not how the language is designed to be used.

Perhaps from your description you're in the situation where the input document contains escaped markup, and you want the output to contain unescaped markup. Escaped markup is bad design, but it's used suprisingly often. One solution is to parse the input twice, by using an extension such as saxon:parse(). Another solution is to suppress the escaping of the output using disable-output-escaping="yes". But remember that isn't supported in all environments, it only works where the XML is being serialized, which means for example it doesn't work in Forefox.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old March 20th, 2009, 09:36 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well if you want XML output then the output will have to follow XML rules, meaning at least the less-than sign '<' needs to be escaped as '&lt;'. And most serializers do escape the greater-than sign '>' as well.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
sunilkswain (March 20th, 2009)
 
Old March 20th, 2009, 09:38 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

If you use XSLT 2.0 and you are sure you don't want well-formed XML output then look into character maps in XSLT 2.0: http://www.w3.org/TR/xslt20/#character-maps
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old March 20th, 2009, 09:40 AM
Registered User
 
Join Date: Mar 2009
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default

As i m new to XSLT serialization could pls give more detail on this?







Quote:
Originally Posted by Martin Honnen View Post
Well if you want XML output then the output will have to follow XML rules, meaning at least the less-than sign '<' needs to be escaped as '&lt;'. And most serializers do escape the greater-than sign '>' as well.

Last edited by sunilkswain; March 23rd, 2009 at 11:46 PM.. Reason: more clarity
 
Old March 20th, 2009, 09:46 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

You seem to use XSLT to transform XML to XML but complain about '<' being escaped as '&lt;' in the result of the XSLT transformation while it has to be that way to have well-formed XML. There is not much you can do about that as long as you want to have XML output. If you don't want/need that then look into character maps, as already suggested.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old March 23rd, 2009, 03:03 AM
Registered User
 
Join Date: Mar 2009
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks Mr Martin Honnen and others.
I got the solution through character-map .


Quote:
Originally Posted by Martin Honnen View Post
You seem to use XSLT to transform XML to XML but complain about '<' being escaped as '&lt;' in the result of the XSLT transformation while it has to be that way to have well-formed XML. There is not much you can do about that as long as you want to have XML output. If you don't want/need that then look into character maps, as already suggested.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Escape ' lafilip XSLT 3 May 22nd, 2007 03:31 AM
how to send escape sequence to printer ergoktas C# 0 November 28th, 2006 04:36 AM
How to Escape Forward Slash in XPath/ XSLT? tclancy XSLT 4 January 10th, 2006 05:28 PM
escape squences in C# kapi.goel C# 7 January 10th, 2006 10:24 AM
xslt issue to translate escape sequence rk2203 XSLT 2 October 13th, 2005 07:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.