473,385 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

XSLT Transform options

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
Nov 12 '05 #1
3 1747
"Paul Hatcher" <ph******@spamless.cix.co.uk> wrote in message news:#i**************@TK2MSFTNGP09.phx.gbl...
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
Nov 12 '05 #2
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" <lo*******@msn.com> wrote in message
news:##*************@tk2msftngp13.phx.gbl...
"Paul Hatcher" <ph******@spamless.cix.co.uk> wrote in message

news:#i**************@TK2MSFTNGP09.phx.gbl...
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

Nov 12 '05 #3
Are you using <xsl:output method="xml" version="1.0"/> in your XSLT?

-Naraen

----
"Paul Hatcher" <ph******@spamless.cix.co.uk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ola Natvig | last post by:
Anybody out there who knows if the 4suite implementation of XSLT are a threadsafe one? -- -------------------------------------- Ola Natvig <ola.natvig@infosense.no> infoSense AS / development
0
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag,...
3
by: Jason S | last post by:
Hello Group, I am just about tearing my hair out with this one and thought someone may have some insight. I have a transform that wasn't working so I grabbed the nearest debugger (xselerator)...
3
by: Alex | last post by:
I stumbled upon this while developing a custom XPathNavigator. It appears that copy action for attributes is broken in the .net framework XSLT processor. The intent was to just copy the entities...
4
by: schneider | last post by:
Anyone know if there is a way to dynamicly create a Xslt template/s and use them as an xml transform with-out use files for the Xslt? All the methods I see use files. I want to create a Xslt...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
2
by: Gabe Moothart | last post by:
Hi, I need some help figuring out how to do something in xslt. I have an xml document with a list of items. Each item in turn can have a list of options, like so: <item> <stuff>Item 1...
1
by: Nick | last post by:
I am working on a website for a client and one of their requirements was to have a mailing list. I decided to XSLT to transform "templates" to HTML so that editing was very easy and less time...
3
by: RC | last post by:
Let's say: if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { // Now I got an XML object here var xmlDocument = XMLHttpRequestObject.responseXML; // next I have...
0
by: SpaceMarine | last post by:
hello, im having a discussion w/ one of my associates, and we're are trying to get a consensus on a possible performance scenario. we're working a/ 3-rd party component that produces PDFs using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.