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 September 18th, 2008, 12:20 PM
Registered User
 
Join Date: Sep 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to use xsl in this scenario

Hi, I'm kind of new to xsl and am thinking of using it in an upcoming project. What I have is a set of different "templates" that have variables in them that I need to combine into one document (this document will eventually be opened by MS Word). Here's an example:

Template 1
Paragraph 1 <insert variable> some more text.

Template 2
Paragraph 2 <insert variable> some more text.

Here's what I'm thinking of doing - store all of my variables in an xml file and then have each template be an xsl file. I think I can have a master xsl document which uses "xsl:include" to reference each of the template xsl files and then process the master xsl file to create the final xml document. Does this sound like a good idea or is there a better way to do this? Should I not be storing my template information as xsl? Should the template content instead be in the xml file and then get processed by the xsl file? Sorry for such noobie questions :) I'd appreciate any help someone could give me.




 
Old September 18th, 2008, 01:40 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm afraid there are many ways of doing this, and it's hard to discuss design issues on a forum like this - it's too open ended and requires a longer attention span than one can give it.

I think you're basically considering two designs, one that has the "fixed" text in an XML source document, one that has it in the stylesheet. Both can work perfectly well. I would say that the choice between the two is best made by thinking about who is responsible for editing and maintaining this text: is it reasonable to expect that this will always be done by someone with XSLT skills?

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old September 18th, 2008, 03:54 PM
Registered User
 
Join Date: Sep 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the quick reply. My hopes are that the person doing the editing will be editing the text and the decision logic, which probably means they will need to edit the xsl file. Are there any good wsywig xsl editors out there that you would recommend?

Also, I noticed that xsl has a xsl:variable element. Is it better to store variables using this element rather than store them in my xml file? If so, I guess I don't even really need my xml file. These variable are coming from a database, so I would have to insert the variables into my xsl file with code and then process it.

 
Old September 18th, 2008, 04:22 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's certainly possible to generate an XML file with a stylesheet of the form

<xsl:param name="p1"/>
<xsl:param name="p2"/>

<xsl:template name="go">
  <boilerplate>
    ....
      <xsl:value-of select="$p1"/>
    ...
      <xsl:value-of select="$p2"/>
  </boilerplate>
</xsl:template>

and then run it by supplying values for $p1 and $p2. In XSLT 2.0, there's no need for a source XML document. In 1.0 there must be a source document (and the above template would say match="/") but the source doc can be a dummy.

In fact today I've been working on the performance of a stylesheet which looks just like this; with the added twist that the stylesheet is generated by the previous step in a processing pipeline.

However, if the structure of the output is more variable than this, for example if it contains a table with a variable number of rows, then you will want to start supplying some structured input, that is, XML input, and this quickly evolves to a model where there is a real source document; and at this point it *might* make sense to put the fixed data in an XML source document as well, for ease of maintenance.

Another system I'm working on uses a mixture of these techniques: most of the final text comes from input documents, but some is in the stylesheet.

As for editors, Stylus Studio, oXygen, and XML Spy all have their fan clubs. I use Stylus Studio myself, partly because they have a business relationship with Saxonica, partly because it does everything I need, and partly because I like the fact that you can use a wide variety of tools (e.g. schema validators) within the same framework.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old September 18th, 2008, 04:28 PM
Registered User
 
Join Date: Sep 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank You! You've been very helpful. I agree if I end up having lots of data where I need to do iterations, then I'll put that information in an xml file. I'll try out those editors too. Thanks again!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi language scenario edgarw BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 May 7th, 2007 08:08 AM
Malicious Code Detect in CallBack Scenario wirerider ASP.NET 2.0 Basics 0 June 26th, 2006 07:39 PM
Scenario tonygreaves BOOK: Professional DotNetNuke ASP.NET Portals ISBN: 0-7645-9563-6 1 September 4th, 2005 01:32 AM
scenario for insert query shankhan Classic ASP Databases 1 April 3rd, 2005 09:50 PM





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