[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Real-time XML to XML Conversion?

Subject: Real-time XML to XML Conversion?
From: "HEATH ALLISON" <HEATH.ALLISON@xxxxxxxxxxxxxxx>
Date: Tue, 10 Jun 2003 11:19:39 -0500
real time xml data
I've been charged with the dubious task of creating an XSLT that will convert XML to XML live. I'm almost there, but I need some help.

First things first... I need to convert this:

<DOCUMENT>
<USER>Agent Smith</USER>
<CLIENTDATA>Asmith</CLIENTDATA>
<CLIENTDATA>33</CLIENTDATA>
<CLIENTDATA>Agent</CLIENTDATA>
<USER>Agent Clyde</USER>
<CLIENTDATA>Aclyde</CLIENTDATA>
<CLIENTDATA>35</CLIENTDATA>
<CLIENTDATA>Agent in Training</CLIENTDATA>
</DOCUMENT>

Into this:

<DOCUMENT>
	<AGENT>
		<AGENTNAME>Agent Smith</AGENTNAME>
		<AGENTID>Asmith</AGENTID>
		<AGENTAGE>33</AGENTAGE>
		<AGENTSTATUS>Viral Agent</AGENTSTATUS>
	</AGENT>
	
	<AGENT>
		<AGENTNAME>Agent Clyde</AGENTNAME>
		<AGENTID>Aclyde</AGENTID>
		<AGENTAGE>35</AGENTAGE>
		<AGENTSTATUS>Agent in Training</AGENTSTATUS>
	</AGENT>
</DOCUMENT>

But I have a problem... I'm getting this:

<DOCUMENT>
<AGENT>
<AGENTNAME>Agent Smith</AGENTNAME>
<AGENTID>Asmith</AGENTID>
<AGENTAGE>33</AGENTAGE>

<AGENTSTATUS>Agent</AGENTSTATUS>Agent Clyde</AGENT>

<AGENT>
<AGENTNAME>Agent Clyde</AGENTNAME>
<AGENTID>Aclyde</AGENTID>
<AGENTAGE>35</AGENTAGE>
<AGENTSTATUS>Agent in Training</AGENTSTATUS>
</AGENT>
</DOCUMENT>

Notice I've got an extra "Agent Clyde" where I should have just the closing </AGENT>.

My XSL looks like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes"/>
<xsl:output indent="yes"/>
<xsl:template match="/">
<DOCUMENT>
	
	<xsl:for-each select="//USER">
	<AGENT>
		<AGENTNAME><xsl:value-of select="."/></AGENTNAME>
        <xsl:apply-templates select="following-sibling::*"/>
	</AGENT>
	</xsl:for-each>

</DOCUMENT>

</xsl:template>

<xsl:template match="//CLIENTDATA">
	<xsl:if test="position()=1">
		<AGENTID><xsl:value-of select="." /></AGENTID>
	</xsl:if>
	<xsl:if test="position()=2">
		<AGENTAGE><xsl:value-of select="." /></AGENTAGE>
	</xsl:if>
	<xsl:if test="position()=3">
		<AGENTSTATUS><xsl:value-of select="." /></AGENTSTATUS>
	</xsl:if>

</xsl:template>
</xsl:stylesheet>


My second question is one of functionality. While what I've tried so far does produce an output file that looks like a new XML file, that's not what I need. I actually need the new XML data to be immediately available to be manipulated by the XSLT which is doing the tree conversion. Make sense?

Oh and finally I'm using an .asp to transform the xsl/xml as follows:

dataFile = Server.mappath("convertxml.xml") 
set XMLDoc = server.createObject("Msxml2.DOMDocument") 
XMLDoc.async = false 
XMLDoc.load dataFile 

set XSLDoc = server.createObject("Msxml2.DOMDocument") 
XSLDoc.async = false 
datafile=server.mappath("convertxml.xsl") 
XSLDoc.load datafile response.write 

XMLDoc.transformNode(XSLDoc) 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.