Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

(XSLT) Using node-set() with string output from a script

Started by kooktroop Apr 17, 2006 at 9:51 PM 0 replies 1.3k views
Original Post
kooktroop
kooktroop
G'day, The aim of what I am doing is to sort through the XML, select the nodes I need and then output them. Currently, I am trying to iterate over the output from a script and display it using XSLT. Although the code below isn't doing anything complex at all, it's is to see how I would nodes from a script to the XSLT. I need the nodes returned from a script because I plan on doing a more complex selection process than XSLT offers. I have the following XSLT as a test script (the XML isn't required because I don't really use it, the main focus is on the msxml:script and the node-set() calls. I'm just trying to get this functionality working):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:msxsl="urn:schemas-microsoft-com:xslt"
	xmlns:msxml="urn:schemas-microsoft-com:xslt"
	xmlns:var="urn:var" 
	xmlns:user="urn:user" 
	exclude-result-prefixes="msxsl var user">
	
	<xsl:template match="//stage">
		<html>
			<head>
				<title>Title</title>
			</head>
			<body>
			<h3>Workbook</h3>
			
			<xsl:element name="p">
				Test: <xsl:value-of select="user:test()" />
			</xsl:element>
			
			<xsl:variable name="test_vardn">
				<xsl:copy-of select="user:test()" />
			</xsl:variable>
			
			Starting output: 
			<xsl:element name="hr" />
			<xsl:for-each select="msxsl:node-set($test_vardn)/deliverableinfo" >
				
					<xsl:value-of select="@name" />
				
			</xsl:for-each>
			<xsl:element name="hr" />
			</body>
		</html>
		
	</xsl:template>
	
	<msxsl:script language="C#" implements-prefix="user"><![CDATA[
	
	string test()
	{
		XmlDocument xmlDoc = new XmlDocument();
		xmlDoc.AppendChild( xmlDoc.CreateElement( "root" ) );
		XmlElement xmlElement = xmlDoc.CreateElement( "deliverableinfo" );
		xmlElement.InnerText = "Figaro.";
		xmlDoc.DocumentElement.AppendChild( xmlElement );

		return "<deliverableinfo name=\"tt\">Mwhuahauha</deliverableinfo><deliverableinfo name=\"_t_\">meow</deliverableinfo>"; //xmlDoc.DocumentElement.InnerXml;
	}
	
	string anothertest()
	{
		return "Mwhuahauhauuahua.";
	}
	
	]]></msxsl:script>

</xsl:stylesheet>
Thanks in advance!
Do not remove a fly from your friend's forehead with a hatchet.Chinese Proverb

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.