Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 15th, 2011, 11:06 AM
Authorized User
 
Join Date: Dec 2010
Posts: 16
Thanks: 5
Thanked 0 Times in 0 Posts
Default Adding GUIDs to XML: XSLT or some other means?

I have a collection of hierarchical XML files that looks like this:

Code:
<container type="Box" >
	<property name="BoxName">Name of box</property>
	<container type="Folder">
		<property name="FolderName">Name of folder</property>
		<container type="Document">
			<content type="text" file=".\DocumentTextFile.txt"/>
			<property name="DocName">Name of document</property>
What I need is to add to each "container" element a GUID property. GUID can be generated in .NET by System.Guid.NewGuid() (http://msdn.microsoft.com/en-us/libr...d.newguid.aspx)

So this would turn the sample above into something like this:

Code:
<container type="Box" >
	<property name="GUID">0f8fad5b-d9cb-469f-a165-70867728950e</property>
	<property name="BoxName">Name of box</property>
	<container type="Folder">
		<property name="GUID">7c9e6679-7425-40de-944b-e07fc1f90ae7</property>
		<property name="FolderName">Name of folder</property>
		<container type="Document">
			<content type="text" file=".\DocumentTextFile.txt"/>
			<property name="GUID">7c9e6679-7425-abcd-944b-e07fc1708677</property>
			<property name="DocName">Name of document</property>
What would be the best way to do that? Does XSLT have capabilities to generate a GUID? If not, it seems that the only way to do this is in C#. Or is there another way?

Thanks much!
 
Old February 15th, 2011, 11:12 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Assuming you use an XSLT processor like System.Xml.Xsl.XslCompiledTransform you can access .NET framework functionality in your XSLT stylesheet, either by using an extension function (i.e. with msxsl:script element) or by using an extension object. See http://msdn.microsoft.com/en-us/library/6datxzsd.aspx for details.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old February 15th, 2011, 04:01 PM
Authorized User
 
Join Date: Dec 2010
Posts: 16
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Martin Honnen View Post
Assuming you use an XSLT processor like System.Xml.Xsl.XslCompiledTransform you can access .NET framework functionality in your XSLT stylesheet, either by using an extension function (i.e. with msxsl:script element) or by using an extension object. See http://msdn.microsoft.com/en-us/library/6datxzsd.aspx for details.
Martin,

Thanks for the link. I have a follow-up question, though. From what I've read, this seems to require calling XSLT from .NET code, which would in turn call a .NET method (public double circumference() in the their example). But what if I want to use a stylesheet with a call to msxml or a tool like Saxon? Can I still insert C# code into XSLT and have it interpreted/compiled correctly?

Thanks!
 
Old February 15th, 2011, 04:26 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

No. MSXML allows extension methods to be written in javascript (or JScript to be more correct) or vbscript, which in theory could then create COM objects which could wrap a .Net assembly. Saxon extension methods would need to be written in java, or if you are using Saxon inside .Net you could write then in .Net I think.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Guids mlw C# 2008 aka C# 3.0 5 June 23rd, 2008 03:52 PM
Where are the GUIDS Bob Bedell Pro VB 6 2 January 2nd, 2006 10:49 AM
Adding XSLT transformed XML content dynamically jacob ASP.NET 1.x and 2.0 Application Design 2 December 1st, 2005 04:40 PM
What is OleDBDataReader.GetValue() means? Dragonist ADO.NET 2 July 5th, 2004 07:24 PM
What does it means in a EXCEL formula?! aarias Excel VBA 1 October 2nd, 2003 02:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.