Re: [xsl] Efficiency, use param in key?

Subject: Re: [xsl] Efficiency, use param in key?
From: "Robert S. Koberg" <rob@xxxxxxxxxx>
Date: Sat, 03 Aug 2002 04:25:34 -0700
Hi Chris,
[name sounds familiar, Authorware? Director?]

First, people who storyboard their projects are some of the smartest people :-D

Christopher_Dant@xxxxxxxxxxxxxx wrote:
On working a stylesheet that processes a multimedia-course storyboard and
returns text, CRLF-delimited, sorted, lowercase, no-duplicates filenames I
have several questions:

Second, I am not too clear on the desired outcome.

1. is there anything I should do to improve it (make it more efficient)?

2. is it possible to use the param "ele" in key, apply-templates and
template? This would make it possible for a single stylesheet to look for
file_audio, file_video or file_graphic tags.

No you can't do that.

If you are making a storyboard, why do you need to get all of these at once? in sorted order?

3. Or perhaps I should actually ask, is there a way to rework my approach so I can parameterize it?

Can you show the output you are trying to achieve?


<xsl:output method="text" encoding="ISO-8859-1" indent="no"/>

<xsl:param name="ele">file_audio</xsl:param>

Here you could pass in the param from the server (or a client-side app). So all you need at the top level is:

<xsl:param name="ele"/>

<xsl:variable name="lc" select="'abcdefghijklmnopqrstuvwxyz'"/> <xsl:variable name="uc" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>

<xsl:key name="fn" match="file_audio" use="@fileref"/>

<xsl:template match="/">
    <xsl:apply-templates select="//file_audio">
        <xsl:sort select="@fileref"/>

You almost never want to use '//' to find things. This is a big slowdown. Are you trying to create a report of all your media assets? If so, it might not matter that the performance is bad.

<xsl:template match="file_audio[generate-id() = generate-id(key('fn', @fileref)[1])]"> <xsl:value-of select="translate(@fileref, $uc, $lc)"/> <xsl:text disable-output-escaping="yes">&#xD;&#xA;</xsl:text> </xsl:template>

Ah.. you just want a list of assets and to ensure all the names are lowercase

You don't need the elaborate match. In your match="/" you set up everything to be fed to the template directly above. So all you need is:

<xsl:template match="file_audio">

I am not sure what you are trying to do here:

<xsl:text disable-output-escaping="yes">&#xD;&#xA;</xsl:text>

Excerpts of sample input:

<frame id="01" type="a" parms="a">
<txt_scr lang="ENG"/>
<txt_aud>Click on a button in front of the module you wish to begin
<file_audio fileref="coursemenu.mp3"/>
<frame id="01">
<txt_scr lang="ENG">Welcome to the Intercom Plus training!</txt_scr>
<txt_avi>{Zelda} Hi, welcome to the Intercom Plus Training! I am Zelda
<file_avi start_frame="1" end_frame="359" fileref="__A_.0010.001.avi" />

Chris, you can contact me offlist if you want more specific stuff as it relates to a MACR product.

I don't understand why you need to get the media assets all at once. For a storyboard that I have in mind you would want to keep the asset with the frame. Can you elaborate on what you need.

You might want to keep your assets in different files and refer to them by ID. So you might have:

  <movie start_frame="1" label="jkhjh" end_frame="359" id="amovie.avi">
    <text id="text1.xml"/>
   <movie start_frame="1" label="jkhjh" end_frame="359" id="amovie2.avi">
    <text id="text2.xml"/>
    <movie start_frame="1" label="jkhjh" end_frame="359" id="amovie_n.avi">
    <text id="text_n.xml"/>

  <clip id="amp3.mp3" label="jkhjh" more_meta_data="whatever"/>
  <clip id="amp3_n.mp3" label="jkhjh" more_meta_data="whatever"/>

  <screen_text id="screen1.xml" label="jkhjh"/>
  <screen_text id="screen2.xml" label="jkhjh"/>

[cbt.xml] <cbt> <chapter id="chap1" title="blah blah"> <frame id="f1" etc="etc" blah="blah"> <screen_text id="screen1.xml"/> <movie id="amovie.avi"/> </frame> <frame id="f2" etc="etc" blah="blah"> <screen_text id="screen2.xml"/> <clip id="amp3.mp3"/> </frame> </chapter> </cbt>

Here, your main source document is cbt.xml. In your primary XSL you can define a key to account for all XML documents you bring into the transformation, like:

<xsl:key name="main_key" match="chapter | frame | screen_text | clip | movie | clip" use="@id"/>

As you go through you main source XML (cbt.xml) you come across your different assets you can access their specific info by doing something like:
<!-- top-level variable -->
<xsl:variable name="movies_nodeset" select="document('movies.xml')/movies"/>

<!-- perhaps you need to get all of the particular movie's info -->
<xsl:template match="movie">
  <xsl:variable name="movie_id" select="@id"/>
<!-- change the XML context to the movies.xml so you can use key() -->
  <xsl:for-each select="$movies_nodeset/movie">
     <xsl:apply-templates select="key('main_key', $movie_id)" mode="info"/>

<xsl:template match="movie" mode="info">
<!-- now you are in movies.xml at the node specified by the key above -->

  <xsl:value-of select="@id"/>
  <xsl:text>, </xsl:text>
  <xsl:value-of select="@label"/>
  <xsl:text>, </xsl:text>
  <xsl:value-of select="@start_frame"/>
  <xsl:text>, </xsl:text>
  <xsl:value-of select="@end_frame"/>
  <xsl:text>, </xsl:text>


best, -Rob Koberg



Christopher Dant
Technology Director
Jack Morton Worldwide

XSL-List info and archive:

XSL-List info and archive:

Current Thread