Re: [xsl] foreign keys in a xml-database

Subject: Re: [xsl] foreign keys in a xml-database
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Tue, 07 May 2002 22:04:24 +0200
ChivaBaba@xxxxxxx wrote:
The Stylesheet I use, transforms the first.xml into html-files.
> The problem I got in my xsl-file now,is that I need to output
> for each project the included tools sorted first by category
> and second by name.

You could setup a two pass processing (preferred), firts
pass merginig, second pass sorting, or refer to the data
directly. The latter is likely expensive.

The first difficuilty is, that I want only those release-nodes
> (childs of tools from second.xml) to be copied, whose name fits
> the version-attribute of the current tool-node in first.xml.

You probably need a composite key.

  <xsl:key name="tool-version" match="tool"
     use="concat(@name,'#',release/@name)"/>
  <!-- convenience variable holding second.xml -->
  <xsl:variable name="tool-def" select="document('second.xml')"/>

  <xsl:template match="project">
    ...
    <xsl:for-each select="tool">
      <!-- build the key of the tool used -->
      <xsl:variable name="key" select="concat(@name,'#',@version)"/>
      <!-- change context for key lookup -->
      <xsl:for-each select="$tool-def">
        <xsl:apply-templates select="key('tool-version',$key)"/>
      </xsl:for-each>
      ...
    </xsl:for-each>
   </xsl:template>

Define appropriate templetes to copy the stuff you need from
the tool detail definition data.

Building the two pass approach can be done using an
intermediate file if you are using the XSLT processor from
the command line, or using the first pass transformer as
SAXFilter and pipe the result to the second. This requires
two style sheets, of course, one for merging and the second
for sorting.
In order to have one style sheet only you can store the result
of the merge in a variable and use exsl:node-set() to convert
it into a sortable node set:

  <xsl:template match="project">
    <xsl:variable name="merge-result">
      <xsl:for-each select="tool">
       ...
    </xsl:variable>
    <xsl:for-each select="exxl:node-set($merge-result)">
      <xsl:sort select="@category">
      <xsl:sort select="@name">
       ... produce your HTML here...
    </xsl:for-each>

J.Pietschmann



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


Current Thread