This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
SOLUTION: namespaces issue
- From: "Snow, Corey" <csnow at deltadentalwa dot com>
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Mon, 24 Jun 2002 11:21:54 -0700
- Subject: [xsl] SOLUTION: namespaces issue
- Reply-to: xsl-list at lists dot mulberrytech dot com
A while back, I posted a question regarding getting fully
namespace-qualified XML out of content that was escaped. I received a couple
of responses, for which I am very grateful.
The suggestions I received were to use the XSL functions such as
substring-before, replace() and substring-after to search for instances of a
given namespace declaration, then put the appropriate "xmns" attribute at
that point. This was problematic in cases such as:
<elementname xlink:type="simple" xlink:href="target.html"/>
For which I needed to obtain:
<elementname xmns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple"
xlink:href="target.html"/>
I couldn't do a simple search/replace on something like this or I'd end up
with multiple xmlns: attributes. A more complex search/replace template
using XSL was doable, but I settled on using an extension function. I
decided that since I was already in for a penny in terms of portability, I'd
go for the pound as well. When I start receiving well-formed XML from this
system in future versions I can get rid of all this jiggery-pokery to get
the stuff working.
At any rate, I wrote an extension function in VBScript, viz:
<msxsl:script language="VBScript" implements-prefix="wds">
<![CDATA[
Function ConvertSerializedXMLToNodeList(strXML)
Dim objXML
Dim objDocFragment
Dim objChild
Set objXML=CreateObject("MSXML2.DOMDocument.4.0")
objXML.async=False
If Not objXML.loadXML("<root
xmlns:xlink='http://www.w3.org/1999/xlink'>" & strXML & "</root>") Then
ConvertSerializedXMLToNodeList="Error: " &
objXML.parseError.reason
Else
Set objDocFragment=objXML.createDocumentFragment
For Each objChild in
objXML.documentElement.childNodes
objDocFragment.appendChild objChild
Next
ConvertSerializedXMLToNodeList=objDocFragment.xml
End if
Set objXML=Nothing
Set objDocFragment=Nothing
End Function
]]>
</msxsl:script>
and to get the appropriately-escaped XML, I do the following:
<xsl:element name="content">
<xsl:value-of
select="wds:ConvertSerializedXMLToNodeList(string($serialized-xml))"
disable-output-escaping="yes"/>
</xsl:element>
Where $serialized-xml is the escaped XML, obviously. This is about the
ugliest hack I've ever had to do, but it works and I'm satisfied with that
for now. At least when this transformation process is done, I've got nicely
formed XML.
Thanks for the responses on my original question,
Corey Snow
#########################################################
The information contained in this e-mail and subsequent attachments may be privileged,
confidential and protected from disclosure. This transmission is intended for the sole
use of the individual and entity to whom it is addressed. If you are not the intended
recipient, any dissemination, distribution or copying is strictly prohibited. If you
think that you have received this message in error, please e-mail the sender at the above
e-mail address.
#########################################################
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list