[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Default template match

Subject: Re: Default template match
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 3 Dec 2001 13:28:14 +0000
xsl doc ref
Hi Costantino,

> Therefore, how can I refer to the specific customer (from the
> "metadata" file), when I am applying other templates?

Passing it down as a parameter is the only way of doing it.

By the way, you could make your stylesheet more readable and efficient
by changing the way that you access the information in the
metadata.xml document so that you use a key instead. Create a key that
indexes each doc element by its label and lang attributes, as follows:

<xsl:key name="docs" match="doc" use="concat(@lang, '::', @label)" />

Then change your code as follows:

  <!-- iterate over each doc from metadata.xml -->
  <xsl:for-each select="document($metadata)/data/doc">
    <!-- assign the doc to the $doc-ref variable -->
    <xsl:variable name="doc-ref" select="." />

    <doc>
      <!-- create the metadata element for the doc -->
      <metadata><xsl:copy-of select="*" /></metadata>

      <!-- change context to templates.xml -->
      <xsl:for-each select="document($templates)">
      
        <!-- use the key to get hold of the doc -->
        <xsl:variable name="doc"
           select="key('docs', concat($doc-ref/label, '::',
                                      $doc-ref/customer/language))" />

        <!-- create the object and content elements for the doc -->
        <object>
          <xsl:apply-templates select="$doc/object">
            <xsl:with-param name="doc-ref" select="$doc-ref" />
          </xsl:apply-templates>
        </object>
        <content>
          <xsl:apply-templates select="$doc/content">
            <xsl:with-param name="doc-ref" select="$doc-ref" />
          </xsl:apply-templates>
        </content>
      </xsl:for-each>
    </doc>
  </xsl:for-each>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.