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

template processing with document() selected nodes

Subject: template processing with document() selected nodes
From: Richard Lewis <richardlewis@xxxxxxxxxxxxxx>
Date: Tue, 17 Oct 2006 17:01:41 +0100
document.selected
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:
<document>
  <section id=".." title="...">
    <!-- mixed element and CDATA content -->
  </section>
  <!-- more sections -->
</document>

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

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

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

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" />
</xsl:template>

This doesn't work as the XPath:

//file[@orig-src=$src]/@new-filename

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:

document('map.xml')/map/files/file[@orig-src=$src]/@new-filename

Is this expected behaviour?

Cheers,
Richard
-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Richard Lewis
Sonic Arts Research Archive
http://www.sara.uea.ac.uk/
JID: ironchicken@xxxxxxxxxxxxxxx
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

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-2011 All Rights Reserved.