XSLTGeneral 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 .
I have a need to replace all GUID (or UID consist of 32 character) in an installation project file (xml format). I wrote a xsl which replaces all uid elements with the one I specify in <uid>. Since UID must be unique, I must come up a way to insert individual UID. I can generate the UID in Java code. I am thinking (not sure it's possible) two ways of handling this: one is to generate a list of UID in an xml file, and import each UID to each <uid> element. Second is to invoke the function that returns the UID directly in xsl.
I am new to xsl, so I appreciate your help in this issue. Thanks!
Both techniques are possible. Writing a file containing the mappings from old to new UIDS is probably cleaner, because calling Java extension functions is processor-dependent.
Michael Kay http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Could you point me to some reference online or books that talk about the mapping technique? Or perhaps, you can provide me with a sample code? I am planning to have the guid.xml for my GUID entries:
You use the document() function to read the XML (or you can pass it as a parameter to your stylesheet, and then you locate the elements within it using path expressions just as in your primary document.
Michael Kay http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
With the document() function, I was able to retrieve the data from an external xml file. However, It writes all UID with the first GUID. I know that somehow I need to use a loop or some reference to the next element in guid.xml, but just not sure where. could you shine some light?
because you can't use xsl:param here. (If you don't get an error, it's a bug in your XSLT processor). However, what you are trying to do is basically flawed, because XSLT, as a functional programming language, doesn't have updatable variables. You need to think of this as a function: calculate the variable $n as a function of something in your input. It might be as simple as position(), or something more complicated involving xsl:number.
Michael Kay http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference