471,594 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

Simple issue with XSLT Extension Objects

Hi, I've a simple issue with the use of extension objects.

I'm trying to call a text formating method from an object that I add to
my arguments collection, this method take an input string and output
the formatted string.

So far everything process correctly (the method is called without any
issue) but my problem is that the output is htmlencoded, it means that
my method (wich work as intended in other contexts) is called but the
output is automatically encoded (& become & etc.)

If you need further explanation here is a simple testcase that
illustrate my issue:

Main.cs
================================
using System;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
class XSLTSimpleTest
{
static void Main()
{
XPathDocument xmldoc = new XPathDocument(new
System.IO.StringReader("<doc/>"));
XslTransform xslt = new XslTransform();
xslt.Load("test.xslt");
XsltArgumentList args = new XsltArgumentList();
args.AddExtensionObject("myObjects:DotNetString"," Lorem ipsum...");
// this Transform method signature is obsolete, but only used for
demonstration purpose
xslt.Transform(xmldoc, args, Console.OpenStandardOutput());
args.Clear();
args.AddExtensionObject("myObjects:DotNetString"," Lorem
<em>ipsum...</em>");
xslt.Transform(xmldoc, args, Console.OpenStandardOutput());
}
}
================================

test.xslt
================================
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:DotNetString="myObjects:DotNetString">
<xsl:template match="/*">
<strong><xsl:value-of select="DotNetString:Substring(0, 1)"
/></strong><xsl:value-of select="DotNetString:Substring(1)" />
</xsl:template>
</xsl:stylesheet>
================================

the output of this program is (it isn't event a valid xml doc...):
================================
++<?xml version="1.0" encoding="utf-8"?>
<strong xmlns:DotNetString="myObjects:DotNetString">L</strong>orem
ipsum...++<?
xml version="1.0" encoding="utf-8"?>
<strong xmlns:DotNetString="myObjects:DotNetString">L</strong>orem
&lt;em&gt;ips
um...&lt;/em&gt;
================================

where I would want:
================================
++<?xml version="1.0" encoding="utf-8"?>
<strong xmlns:DotNetString="myObjects:DotNetString">L</strong>orem
ipsum...++<?
xml version="1.0" encoding="utf-8"?>
<strong xmlns:DotNetString="myObjects:DotNetString">L</strong>orem
<em>ips
um...</em>
================================

So anyone's help would be appreciated.

Thanks

Gauthier Segay
Nov 12 '05 #1
4 1846
Hello, Gauthier!
You wrote on Thu, 08 Apr 2004 21:33:19 -0700:
[Sorry, skipped]

Modify the xslt with

<xsl:value-of select="DotNetString:Substring(1)"
disable-output-escaping="yes"/>

With best regards, Alex Shirshov.
Nov 12 '05 #2
g
Thanks Alex!

Needless to say that I'm a XSLT newbie ;)

Gauthier Segay

Alex Shirshov wrote:
Hello, Gauthier!
You wrote on Thu, 08 Apr 2004 21:33:19 -0700:
[Sorry, skipped]

Modify the xslt with

<xsl:value-of select="DotNetString:Substring(1)"
disable-output-escaping="yes"/>

With best regards, Alex Shirshov.


Nov 12 '05 #3
As a side note, this works only when using something other than
XmlTextWriter, because it seems to enforce encoding.

So I've switched to a simple StreamWriter that keep my bits running
without encoding.

Since it took me some correct/rebuild steps to figure it out, it's
better to report it here with accessible keywords as message subject :)

Gauthier Segay
Nov 12 '05 #4
Gauthier wrote:
So far everything process correctly (the method is called without any
issue) but my problem is that the output is htmlencoded, it means that
my method (wich work as intended in other contexts) is called but the
output is automatically encoded (& become &amp; etc.)


Return it as XPathNodeIterator (represents XPath's nodeset) instead of
string to avoid output encoding.
Otherwise use disable-output-escaping (beware it's ignored when
transforming to XmlWriter ot XmlReader).

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Gordan | last post: by
1 post views Thread by Diego Rivero | last post: by
7 posts views Thread by Harolds | last post: by
1 post views Thread by =?Utf-8?B?UHJhc2hhbnQgQw==?= | last post: by
3 posts views Thread by WideBoy | last post: by
11 posts views Thread by Ebenezer | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.