Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 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 10th, 2006, 01:35 PM
Registered User
 
Join Date: Feb 2006
Location: , , Switzerland.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default xslt with an xslt outputfile

Hi@all

I have the following xml-file:

---------------------------
source.xml

<document>
    <sourcefile>/export/website/index.xhtml</sourcefile>
    <sourcefile>/export/website/info.xhtml</sourcefile>
    . . . and so on . . .
</document>
---------------------------

Now I need to make an xslt-file (process.xsl) which produces another xslt-file (result.xsl) as result.

result.xsl first creates an xhtml-head and saves this in output.xhtml (head means <html><head><title></title></head><body>-tags).
After that there must be (for every sourcefile out of source.xml) a command like: document(/export/website/index.xhtml).
If the xhtml-file was opened (in this case index.xhtml) every information in the <body>-tags need to be copied and pasted into output.xhtml.
If every sourcefile was added to output.xhtml the final </body> and </html>-tags need to be attached and it's done!

So - any idea how to solve this problem (or better: how process.xsl need to look like)? I'm glad for every hint!

 
Old February 10th, 2006, 01:50 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm not sure where you're having difficulty, or exactly what your requirements are, so it's not easy to provide specific help.

However, please don't think of XSLT in terms of "write the start tag, then write the content, then write the end tag". XSLT creates trees, which are then serialized. The first thing you do is to create an HTML element node on the tree, then you create other nodes as its children. So creating a start tag and end tag are not two separate operations, they are a single indivisible act. I mention this because if you think of them as separate actions you get into all kinds of programming muddles.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 15th, 2006, 08:42 AM
Registered User
 
Join Date: Feb 2006
Location: , , Switzerland.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

All right, in this case I misunderstood XSLT (forgive me this, because I'm a newbie...).

What I try to do is:
We have lots of Webpages in XHTML. They looks like


---------------------------
/export/website/index.xhtml

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="../../site/transform.xsl"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Any Title</title>
    <meta name="id" content="/export/website/index.xhtml"/>
    <meta name="contact" content="display"/>
    <meta name="print-type" content="broshure"/>
    <meta name="print-style" content="broshure.xsl"/>
  </head>
  <body>
  . . . specific content . . .
  </body>
</html>
---------------------------


Now it's my Job to merge all the body contents into ONE (new constructed) XHTML file. This should make the XSLT file (the one I need to write now) which is applied at the source file source.xml.
in source.xml there are all path definitions of the webpages which should be merged.


---------------------------
/export/website/source.xml

<document>
    <sourcefile>/export/website/index.xhtml</sourcefile>
    <sourcefile>/export/website/info.xhtml</sourcefile>
    . . . and so on . . .
</document>
---------------------------

I just don't know how to do this. What I could need is a hint how I could solve it.
Thanks for replying!

 
Old February 15th, 2006, 07:21 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It depends a little how exactly you want to do the merging, e.g. what the title of the merged file should be. But in principle, you need to apply a transformation with source.xml as the input, which looks something like this:

<xsl:template match="/">
 <h:html>
   <h:head>...</h:head>
   <h:body>
     <xsl:copy-of select="document(document/sourcefile)//h:body/*"/>
   </h:body>
 </h:html>
</xsl:template>

where prefix h is bound to the XHTML namespace.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 20th, 2006, 09:56 AM
Registered User
 
Join Date: Feb 2006
Location: , , Switzerland.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

1. What the title of the merged file should be:
The title can be the one from the first (source-)file.



2. You wrote:

   <xsl:copy-of select="document(document/sourcefile)//h:body/*"/>

How would this look like when there must be the complete filename? perhaps like this?

   <xsl:copy-of select="document('/export/website/source.xml')/document/sourcefile//h:body/*"/>



3. How would you change this file(we can call it start.xsl), if the workflow should look like this:

start.xsl [just here to generate merge.xsl!]
  ¦
  ¦ start.xsl is applied on source.xml = merge.xsl as result
 \/
source.xml [the file with all path inforamtions from the sourcefiles]
  ^
  ¦ merge.xsl applied on source.xml = result.xhtml as result
  ¦
merge.xsl [in fact the on file that creates the xhtml-file, the only reason why applying merge.xsl on source.xml is, than you need an xml to execute an xsl! later on there will be some variables in source.xml which need to be added to result.xhtml]

result.xhtml [an xhtml with all body-contents]



this is how my instruction are. or would you recommend me an easier way. perhaps with just one xsl?

thanks!







Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating XSLT with XSLT stonis XSLT 3 April 1st, 2008 08:17 PM
General XSLT Questions in the XSLT Forum jminatel BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 0 March 31st, 2008 07:50 PM
need help on XSLT misanaka XSLT 5 March 23rd, 2007 11:26 AM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM





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