473,785 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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='f red' />

but if I use the XslTransform class I get

<mySchema rdf:resource='f red'></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 1788
"Paul Hatcher" <ph******@spaml ess.cix.co.uk> wrote in message news:#i******** ******@TK2MSFTN GP09.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='f red'></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 WriteFullEndEle ment( ) 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 WriteFullEndEle ment() {
base.WriteEndEl ement();
}
}
- - -

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.CreateNa vigator,
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:##******** *****@tk2msftng p13.phx.gbl...
"Paul Hatcher" <ph******@spaml ess.cix.co.uk> wrote in message

news:#i******** ******@TK2MSFTN GP09.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='f red'></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 WriteFullEndEle ment( ) 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 WriteFullEndEle ment() {
base.WriteEndEl ement();
}
}
- - -

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.CreateNa vigator,
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******@spaml ess.cix.co.uk> wrote in message
news:%2******** ********@TK2MSF TNGP09.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='f red' />

but if I use the XslTransform class I get

<mySchema rdf:resource='f red'></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
1918
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
2358
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, such as a div with a runat=server. I can somewhat do this if I create a server control and include the control within the html div tag but this method (borrowed from ASP.NET Website Programming by Wrox press thanks guys) does not give me the full...
3
2479
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) and saw that it works just fine. Now what I mean by not working is that it just silently fails to produce the expected output... no exceptions are being thrown. Xselerator uses msxml 3 so it's not really helping me see the problem in .net 1.1. ...
3
1761
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 and attributes from the source XML into the output using simple "identity" like XSLT: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/>
4
4824
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 transform via code? Any examples would be great.
7
2869
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 parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("pmID", "", pmID); xmlItems.TransformArgumentList = xsltArgList;
2
1716
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 Stuff</stuff> <option> <option_stuff>Option 1 Stuff</option_stuff> </option>
1
2743
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 consuming. I keep getting the following error when I submit my email to their site. System.Xml.Xsl.XslTransformException: Cannot find the script or external object that implements prefix 'ext:MailingList'. at...
3
1688
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 dealing with XML file tags used DOM. var options = xmlDocument.getElementsByTagNameNS(null,"myXMLTag"); doMyFunctionWithHTMLDOM(options);
0
2415
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 "XML-FO", a verbose description & layout doc. it can accept either: 1) a complete, verbose XML-FO doc 2) data-only XML, plus an XSLT doc to produce valid verbose XML-FO, which it transforms
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9949
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.