HighTechTalks DotNet Forums  

XSLT Transform options

Dotnet XML microsoft.public.dotnet.xml


Discuss XSLT Transform options in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Paul Hatcher
 
Posts: n/a

Default XSLT Transform options - 04-06-2004 , 04:25 PM






Hi

Is it possible to control the node style that XslTransform uses to output
XML?

I'm trying to convert a file from XML to RDF and if I do the transform in
XmlSpy I get the following

<mySchema rdf:resource='fred' />

but if I use the XslTransform class I get

<mySchema rdf:resource='fred'></mySchema>

Unfortunately, my RDF parser doesn't like the second form, so I want to know
if it's possible to tell XslTransform to use the shortened notation?

TIA

Paul



Reply With Quote
  #2  
Old   
Derek Harmon
 
Posts: n/a

Default Re: XSLT Transform options - 04-06-2004 , 09:50 PM






"Paul Hatcher" <phatcher (AT) spamless (DOT) cix.co.uk> wrote

Quote:
Is it possible to control the node style that XslTransform uses to output
XML?
Not directly on the XslTransform class, but there is a way (see below).

: :
Quote:
but if I use the XslTransform class I get

mySchema rdf:resource='fred'></mySchema

Unfortunately, my RDF parser doesn't like the second form,
This is a bug in the RDF parser. The Infoset represented by both
serializations is identical.

The reason XSLT doesn't address this is that the particulars of the
XML syntax are irrelevant to the document's content (i.e., it doesn't
matter whether double-quote or single-quote is used to delimit the
attribute values, or empty tags are rendered one way or another).

: :
Quote:
if it's possible to tell XslTransform to use the shortened notation?
An XmlTextWriter can be wrapped around the output from
XslTransform's Transform( ) method. This XmlTextWriter
can intercept calls to the WriteFullEndElement( ) method,
which XslTransform uses, and replace them with calls to
WriteEndElement( ). WriteEndElement( ) will produce the
shortened end tag when the element has no content.

Here is the code,

- - - XmlTextWriterEE.cs (complete)
using System;
using System.IO;
using System.Xml;

/// <summary>
/// Wrapper that forces shortened empty element end tags to
/// be rendered when possible.
/// </summary>
public class XmlTextWriterEE : XmlTextWriter
{
public XmlTextWriterEE( TextWriter sink) : base( sink) {;}
public override void WriteFullEndElement() {
base.WriteEndElement();
}
}
- - -

The way this might work with an XslTransform, named transformerObj,
would be to wrap some TextWriter (in this example, I wrap the Console
output stream, i.e., stdout).

transformerObj.Transform( xmlDoc.CreateNavigator,
null, new XmlTextWriterEE( Console.Out) );

The XmlTextWriterEE silently intercepts calls that instruct it to write
a full end tag (for instance, to be more compatible with HTML) and
redirects them to the method that'll write out a shortened end tag
for empty elements.


Derek Harmon




Reply With Quote
  #3  
Old   
Paul Hatcher
 
Posts: n/a

Default Re: XSLT Transform options - 04-07-2004 , 02:23 AM



Derek

Thanks for that - it was my understanding also that the two forms were
semantically indentical, unfortunately I can't control which RDF parser we
use and I'm under a deadline.:-(

Paul

"Derek Harmon" <loresayer (AT) msn (DOT) com> wrote

Quote:
"Paul Hatcher" <phatcher (AT) spamless (DOT) cix.co.uk> wrote

Is it possible to control the node style that XslTransform uses to
output
XML?

Not directly on the XslTransform class, but there is a way (see below).

: :
but if I use the XslTransform class I get

mySchema rdf:resource='fred'></mySchema

Unfortunately, my RDF parser doesn't like the second form,

This is a bug in the RDF parser. The Infoset represented by both
serializations is identical.

The reason XSLT doesn't address this is that the particulars of the
XML syntax are irrelevant to the document's content (i.e., it doesn't
matter whether double-quote or single-quote is used to delimit the
attribute values, or empty tags are rendered one way or another).

: :
if it's possible to tell XslTransform to use the shortened notation?

An XmlTextWriter can be wrapped around the output from
XslTransform's Transform( ) method. This XmlTextWriter
can intercept calls to the WriteFullEndElement( ) method,
which XslTransform uses, and replace them with calls to
WriteEndElement( ). WriteEndElement( ) will produce the
shortened end tag when the element has no content.

Here is the code,

- - - XmlTextWriterEE.cs (complete)
using System;
using System.IO;
using System.Xml;

/// <summary
/// Wrapper that forces shortened empty element end tags to
/// be rendered when possible.
/// </summary
public class XmlTextWriterEE : XmlTextWriter
{
public XmlTextWriterEE( TextWriter sink) : base( sink) {;}
public override void WriteFullEndElement() {
base.WriteEndElement();
}
}
- - -

The way this might work with an XslTransform, named transformerObj,
would be to wrap some TextWriter (in this example, I wrap the Console
output stream, i.e., stdout).

transformerObj.Transform( xmlDoc.CreateNavigator,
null, new XmlTextWriterEE( Console.Out) );

The XmlTextWriterEE silently intercepts calls that instruct it to write
a full end tag (for instance, to be more compatible with HTML) and
redirects them to the method that'll write out a shortened end tag
for empty elements.


Derek Harmon





Reply With Quote
  #4  
Old   
NaraendiraKumar R. R.
 
Posts: n/a

Default Re: XSLT Transform options - 04-07-2004 , 02:30 AM



Are you using <xslutput method="xml" version="1.0"/> in your XSLT?

-Naraen

----
"Paul Hatcher" <phatcher (AT) spamless (DOT) cix.co.uk> wrote

Quote:
Hi

Is it possible to control the node style that XslTransform uses to output
XML?

I'm trying to convert a file from XML to RDF and if I do the transform in
XmlSpy I get the following

mySchema rdf:resource='fred' /

but if I use the XslTransform class I get

mySchema rdf:resource='fred'></mySchema

Unfortunately, my RDF parser doesn't like the second form, so I want to
know
if it's possible to tell XslTransform to use the shortened notation?

TIA

Paul





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.