I've done some research online and turned up with results that did not sit well with me. I’m using the System.Xml.XslCompiledTransform class as recommended by MS; however, it’s creating self-closing tags that I don’t want, example:
* My XSLT has: [HTML]<script language="javascript" src="client_scripts/VehInInv.js"></script> [/HTML]
* Using the XslCompiledTransform class I get: [HTML]<script language="javascript" src="client_scripts/VehInInv.js"/>[/HTML] -- notice the missing[HTML] </script> [/HTML] tag
This is not well formed HTML and results in a blank looking page even though a view source of the page I can the rest of the HTML. Is there a way around this through the Transformer MS is telling me to use? Some solutions on the web are to go through each XSLT and replace with empty space in my stylesheet, example:
[HTML]<script language="javascript" src="client_scripts/VehInInv.js"><xsl:text disable-output-escaping="yes">&nbsp;</xsl:text></script>[/HTML]
However, with 60+ stylesheets and the understanding that I could still run into other issues (i.e. using <div></div> or some other empty tag that maybe I’m placing out there to be later manipulated through javascript) I don’t like the idea of this. The transformation function I wrote is below:
Public Function fnTransformXML_new() As String
Dim log As clsLog4Net = Nothing
Dim oParm As clsTransformerParms = Nothing
Dim xslt As XslCompiledTransform
Dim xsltArgList As XsltArgumentList
Dim xDoc As XPathDocument
Dim writer As XmlWriter
Dim reader As XmlReader
Dim stWrite As StringWriter
log = New clsLog4Net
oParm = New clsTransformerParms
xslt = New XslCompiledTransform
xsltArgList = New XsltArgumentList
stWrite = New StringWriter
Dim xsltsettings As XsltSettings = New XsltSettings
xslt.Load(XSL_Path, xsltsettings, New XmlUrlResolver())
Dim xmlsettings As XmlReaderSettings = New XmlReaderSettings
xmlsettings.ConformanceLevel = ConformanceLevel.Fragment
xmlsettings.IgnoreWhitespace = True
reader = XmlReader.Create(New StringReader(XML_String), xmlsettings)
For Each oParm In mCol
If Not IsNothing(oParm) Then
If IsNothing(oParm.ParmValue) Then
xsltArgList.AddParam(oParm.ParmName.ToString, "", "")
Else
xsltArgList.AddParam(oParm.ParmName.ToString, "", oParm.ParmValue.ToString)
End If
End If
Next oParm
writer = New XmlTextWriter(stWrite)
xslt.Transform(reader, xsltArgList, writer)
fnTransformXML_new = stWrite.ToString
End Function
Is there a property of the transformer class that I can turn off/on? Please help.
1 8003 this is a small class i use to solve the problem
Public Class XHTMLWriter : Inherits XmlTextWriter
Public EmptyElements() As String = New String() {"area", "base", "basefont", "br", "col", "frame", "hr", "img", "input", _
"isindex", "link", "meta", "param"}
Private ElementStack As New System.Collections.Stack
Public Sub New(ByVal w As System.IO.Stream, ByVal encoding As System.Text.Encoding)
MyBase.New(w, encoding)
End Sub
Public Overloads Overrides Sub WriteEndElement()
Dim localName As String = CStr(ElementStack.Pop)
If System.Array.IndexOf(EmptyElements, localName) <> -1 Then
MyBase.WriteEndElement()
Else
MyBase.WriteFullEndElement()
End If
End Sub
Public Overloads Overrides Sub WriteStartElement(ByVal prefix As String, ByVal localName As String, ByVal ns As String)
Me.ElementStack.Push(localName)
MyBase.WriteStartElement(prefix, localName, ns)
End Sub
End Class usage:
Public Shared Function myTransform(ByVal xslPath As String, ByVal xDoc As IXPathNavigable, ByRef output As Stream) As Boolean
Dim xslt As XslCompiledTransform = Nothing
With HttpContext.Current
xslPath = .Server.MapPath(xslPath)
If .Cache.Item(xslPath) Is Nothing Then
xslt = New XslCompiledTransform()
xslt.Load(xslPath)
' if the file xslPath is modified the cache will be expired
' warning ! if any include template is modified, the cached object won't be changed
.Cache.Insert(xslPath, xslt, New CacheDependency(xslPath))
Else
xslt = .Cache(xslPath)
End If
End With
Dim ws As XmlWriterSettings = xslt.OutputSettings.Clone()
Dim xw As New XHTMLWriter(output, ws.Encoding)
xw.Formatting = Formatting.Indented
xslt.Transform(xDoc, xw)
Return True
End Function problems:
- <xsl: output ... has no effect
- you must inlude manually doctype in template
<xsl:text disable-output-escaping="yes"><![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/Strict.dtd"> ]]></xsl:text>
Sign in to post your reply or Sign up for a free account.
Similar topics
by: phil_nospam_schmidt |
last post by:
I am trying to prevent a user from resizing a frame beyond its
"natural" size as given by winfo_reqwidth and winfo_reqheight, without
any success. Can anyone make any suggestions, based on my code...
|
by: Eugen Gulinsky |
last post by:
Hello guys,
I am having problems trying to migrate our MSXML4-compatible stylesheets
containing large msxsl:script blocks to a formate understandable by
System.Xml:Xsl.XslTransform. I keep...
|
by: Eckhard Schwabe |
last post by:
when switching from the old "XslTransform " to "XslCompiledTransform"
I notice a difference in the handling of whitespace. I need to transform
a XML file which contain tabs (\t), and which remain...
|
by: Daniel |
last post by:
Does system.xml have any way to transofrm data with an xswl style sheet
using strings like MSXML2 does?
how to convert this to use System.XML so i do not depend on MSXML2 interop?
static...
|
by: W. Jordan |
last post by:
Hello there,
Are there anybody who is using the XslCompiledTransform that comes
with .net framework, which was said to be a replacement of the
XslTransform class?
I found that the class has...
|
by: Hans Kesting |
last post by:
Hi,
In our ASP.Net webapplications, we use xslt a lot. For 1.1 developing was
"easy":
start up the website and go to the page where the xslt was used. Change the
xslt
(save it) and refresh the...
|
by: Mark |
last post by:
I'm getting the error "The URI scheme is too long." in the code below. What
is URI in this context? The XSL or the XML being transformed?
Thanks!
-Mark
StringBuilder sb = new...
|
by: Andy Fish |
last post by:
Hi,
From reading the documentation, I get the impression that
XslCompiledTransform should be faster than XslTransform
on my test with a large complex document and a large complex XSLT, the...
|
by: =?Utf-8?B?Um9iZXJ0?= |
last post by:
Hello all,
I have an XmlException being thrown trying to use XslCompiledTransform while
using the google api. My suspicion is there is some html decoding happening
that I want to prevent...
...
|
by: =?Utf-8?B?d2VqaXY=?= |
last post by:
When I use xslCompiledTransform() or xslCompiledTransform(false) I find that
the XPath queries in my select query attributes do not recognize any
attributes inthe xml document. But when I enable...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
|
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |