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 April 29th, 2007, 02:23 PM
Registered User
 
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems with Document()

Hi all!

I have two xml files for a catalog (Structure.xml) and (Products.xml)an example of each shown below:

Structure.xml

<Structure>
<Section>
        <Title>CD</Title>
    <subsection>
             <Title>CDALBUM</Title>
        </subsection>
        <subsection>
             <Title>CDSingle</Title>
        </subsection>
        <subsection>
             <Title>Compilation</Title>
    </subsection>
    <subsection>
             <Title>Compilation</Title>
        </subsection>
</Section>
</Structure

Products.xml

<Products>
    <Product>
         <displayedin sect="CD" subsect="CDALBUM"/>
         <desc>Crusade - Trivium</desc>
     <desctwo>Genre - Metal</desctwo>
     <Price>8.99</Price>
    </Product>
<Products>

Structure.xml provides a category/subcategory structure and Products.xml will contain product details. In all there will be 4 categories each containing 4 subcategories and i need 1 xslt file to output a html file for each subcategory....

I think i can achieve this by firstly storing Structure/Section/Title as a variable.

Then the next part i need help with...
Maybe something like...

<xsl:variable name="currentsection"select="Structure/Section/Title"/>

<xsl:for-each select="document ('Products.xml')/Products/Product/displayedin[@sect=$currentsection">

(that doesn't work!)

Then something to output a html file for each subsection...

anyone have any ideas?

cheers, mal
 
Old April 29th, 2007, 03:28 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Hi, Welcome to the forum

The following line:

<xsl:for-each select="document ('Products.xml')/Products/Product/displayedin[@sect=$currentsection">

attribute @sect is not part of your xml.



 
Old April 29th, 2007, 04:30 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

To output multiple result documents from a single transformation you need XSLT 2.0 (the xsl:result-document instruction) unless you are prepared to use vendor-specific extensions.

To do joins in XSLT it's generally easiest and most efficient to use keys:

<xsl:key name="k" match="Product"
  use="concat(displayedin/@sect, '/', displayedin/@subsect)"/>


<xsl:for-each select="Structure/Section/subsection">
  <xsl:result-document href="...">
       <xsl:apply-templates select="key('k',
            concat(../Title, '/', ./Title), document('Products.xml')"/>
  </xsl:result-document>
</xsl:for-each>

Then just write a template rule that matches Product.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Document(.....) Ma7T XSLT 1 August 2nd, 2005 06:32 AM
validate.asp problems and logon.asp problems p2ptolu Classic ASP Databases 0 February 16th, 2005 02:34 PM
Document all pallone Javascript How-To 2 January 28th, 2005 01:37 PM
Regarding saving the document Hari_Word Excel VBA 1 October 29th, 2004 10:49 AM





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