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 October 16th, 2007, 11:44 AM
Authorized User
 
Join Date: Jul 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to carlosaml
Default Convert entities...

Hi all

I have an element called <attributes> that has a XML inside, generated by a .NET Dataset (the content is like "&lt;attribute name="test"&gt;My Content&lt;/attribute&gt;" and so on)... I need to make a template in order to make the content a part of the XML itself, converting the entities to real "<" and ">".. How can I do this??


Thx;

 
Old October 16th, 2007, 11:50 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

When you first parse your XML, the &lt; will be turned into <. So the string value of the <attributes> element is a piece of unparsed XML. To turn it into XML that you can process, you need to parse it (that is, to parse it again). Typically this involves invoking the XML parser using an extension function. In Saxon this is built-in (saxon:parse()). In other environments you may be able to write your own.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 16th, 2007, 12:00 PM
Authorized User
 
Join Date: Jul 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to carlosaml
Default

Quote:
quote:Originally posted by mhkay
 When you first parse your XML, the &lt; will be turned into <. So the string value of the <attributes> element is a piece of unparsed XML. To turn it into XML that you can process, you need to parse it (that is, to parse it again). Typically this involves invoking the XML parser using an extension function. In Saxon this is built-in (saxon:parse()). In other environments you may be able to write your own.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Do you have any idea or example of how can I do this?
I'll create a template for doing just that...
Thanks.

 
Old October 16th, 2007, 12:08 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I would also suggest that the DataSet or the original data source is mis-configured if it is escaping the markup. Do you have any control over it?

--

Joe (Microsoft MVP - XML)
 
Old October 16th, 2007, 12:11 PM
Authorized User
 
Join Date: Jul 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to carlosaml
Default

Quote:
quote:Originally posted by joefawcett
 I would also suggest that the DataSet or the original data source is mis-configured if it is escaping the markup. Do you have any control over it?

--

Joe (Microsoft MVP - XML)
The type of my field is xs:string, but it always escapethe characters... I've searched about it and found no way to make the Dataset not to escape entities... Is it possible to make the Dataset generate a unescaped output?

Thanks

 
Old October 16th, 2007, 12:19 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If you can convert it to an XML datatype then I think you can. Can you change the underlying query?

--

Joe (Microsoft MVP - XML)
 
Old October 16th, 2007, 12:24 PM
Authorized User
 
Join Date: Jul 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to carlosaml
Default

Quote:
quote:Originally posted by joefawcett
 If you can convert it to an XML datatype then I think you can. Can you change the underlying query?

--

Joe (Microsoft MVP - XML)
Change the type of the Dataset field or in the database?

I can change in either one (using .NET 1.1 and SQL Server 2k).

 
Old October 16th, 2007, 12:37 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

In that case you may be out of luck, I was hoping for SQL Server 2005. I will investigate.

--

Joe (Microsoft MVP - XML)
 
Old October 16th, 2007, 12:56 PM
Authorized User
 
Join Date: Jul 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to carlosaml
Default

Quote:
quote:Originally posted by joefawcett
 In that case you may be out of luck, I was hoping for SQL Server 2005. I will investigate.

--

Joe (Microsoft MVP - XML)
Hmmm.. Thanks.. I appreciate that..

In the meanwhile... Anyone knows how to convert the entities to the actual symbols via xslt?

thankls

 
Old October 16th, 2007, 01:07 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you're using MSXML, then you can write Javascript code in an <msxsl:script> block which you can invoke from an XPath expression during the course of the transformation (look up "extension functions"). This Javascript code can invoke the MSXML parser on your escaped string and pass back the resulting DOM tree.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Character to Unicode entities Pankaj C XSLT 2 February 15th, 2008 08:59 AM
referenced entities bcogney XML 7 April 21st, 2006 11:04 AM
referenced entities bcogney XSLT 0 April 20th, 2006 02:37 PM
Entities as String muki XSLT 3 November 12th, 2005 12:15 PM
Entities safin XSLT 1 November 7th, 2005 04:59 AM





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