[xsl] template processing with document() selected nodes

Subject: [xsl] template processing with document() selected nodes
From: Richard Lewis <richardlewis@xxxxxxxxxxxxxx>
Date: Tue, 17 Oct 2006 17:01:41 +0100
Hello XSLers,

I've just encountered the following problem:

I have two source XML files, one is my main content file and the other is 
a 'map' file which dictates how the structural elements of the main content 
file should map to the new content file. I have an XSLT stylesheet which 
performs the transformation.

The main content file is the content for my website and it has to be mapped to 
my employer's new content management system which uses "department" to mean 
directory and "article" to mean (roughly) file.

I can't do a straightforward XSLT transformation as the hierarchies of my 
original content and the new CMS are different.

Main content file:
  <section id=".." title="...">
    <!-- mixed element and CDATA content -->
  <!-- more sections -->

Map file:
  <!-- map original sections to new department/articles -->
  <section id="..">
    <in-cms department="..." article="..." />
  <!-- more section mappings -->

  <!-- define the hierarchy of the departments/articles -->
    <department name="..">
      <article name=".." />
      <!-- more articles -->
    <!-- more departments>

  <!-- even the names of resources have to change -->
    <file orig-src="..." new-filename="..." new-id=".." />
    <!-- more files -->

This stylesheet accepts the map file as its source and uses the document() 
function to retrieve the main content. It includes templates which match 
elements from both the map file /and/ the main content file.

It all works fine except for one thing: where I have a template which matches 
one of the elements from the main content file, e.g. "image", I can't seem to 
access the hierarchy of the map file in XPath expressions:

<xsl:template match="image">
  <!-- image has a @src attribute which needs to be looked up in 
map.xml//file[@orig-src=$src] to find the new filename -->
  <xsl:variable name="src" select="@src" />
  <img src="{//file[@orig-src=$src]/@new-filename" />

This doesn't work as the XPath:


doesn't return anything.

(I checked count(//file) and it returned 0)

I managed to get it to work by using the document() function to pull in my 
main input file again:


Is this expected behaviour?

Richard Lewis
Sonic Arts Research Archive
JID: ironchicken@xxxxxxxxxxxxxxx

Current Thread