Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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!
Reply With Quote
  #2 (permalink)  
Old February 15th, 2011, 11:12 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
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
Reply With Quote
  #3 (permalink)  
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!
Reply With Quote
  #4 (permalink)  
Old February 15th, 2011, 04:26 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
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?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:29 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.