Connecting Tech Pros Worldwide Help | Site Map

Simple issue with XSLT Extension Objects

Gauthier
Guest
 
Posts: n/a
#1: Nov 12 '05
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
Alex Shirshov
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Simple issue with XSLT Extension Objects


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.


g
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Simple issue with XSLT Extension Objects


Thanks Alex!

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

Gauthier Segay

Alex Shirshov wrote:
[color=blue]
> 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.[/color]

Gauthier
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Simple issue with XSLT Extension Objects


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
Oleg Tkachenko [MVP]
Guest
 
Posts: n/a
#5: Nov 12 '05

re: Simple issue with XSLT Extension Objects


Gauthier wrote:
[color=blue]
> 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.)[/color]

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
Closed Thread