Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 16th, 2006, 09:24 AM
Authorized User
 
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default Key() ... and XRef

Hallo everyone,

In my XSL, I have declared a number of keys, including the following ...

<xsl:key name="krefplant" match="ref_team" use="PLANT_CODE" />
<xsl:key name="krefteam" match="ref_team" use="TEAM_CODE" />

Then, later in the stylesheet, I use these first to retrieve the PLANT_TEXT:

<td><xsl:value-of select="key('krefplant', $pfiltfld)[1]/PLANT_TEXT" /></td>

... then I get the teamcode (part of a current running definition):

<td><xsl:value-of select="teamcode" /></td>

Then I try to store the teamcode:

$pteamcodestore=<xsl:value-of select="teamcode" />

... to use to retrieve the TEAM_NAME:

<td><xsl:value-of select="key('krefteam', $pteamcodestore)[1]/TEAM_NAME" /></td>

This all works fine (i.e. I can retrieve the PLANT_TEXT) except for the retrieval of the TEAM_NAME. Here, if I hard-code a specific teamcode (e.g. 'abc'), then I get the TEAM_NAME but if I tried to parameterise by grabbing the current teamcode =<xsl:value-of select="teamcode" /> and then either using or storing this, then the processing falls over and the literal values are displayed:

$pteamcodestore=AFB-S

So I imagine that I am trying to do something illegal here: I am trying to take a value retrieved from the current template and use that to filter a Key() clause.

So my question now is whether there is any way around this?

Or maybe I should be approaching the issue in a completely different way?

All I really want to do here is a kind of 'look-up': My template is happily returning the data that I require (relating to team and labelled with teamcode) and so I want to query a list of teams (held in a different place in the same XML file) and return the text description of that team. My code will return the value when I hardcode the criteria but not when I try an pick it up from the current record of the current template.

Am I trying to be too procedural here? Or is there a trick?

Any tips would really help to get me going.

Many thanks,
Alan Searle.

 
Old October 16th, 2006, 10:36 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

$pteamcodestore=<xsl:value-of select="teamcode" />


That's not how you bind a variable in XSLT. Use

<xsl:variable name="pteamcodestore" select="teamcode"/>

(Or select="$teamcode")

I suspect there are other bugs in your code concerning context, but without a source document or real code, as distinct from fragments, I can't be sure.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 17th, 2006, 01:13 AM
Authorized User
 
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,

> That's not how you bind a variable in XSLT. Use
<xsl:variable name="pteamcodestore" select="teamcode"/>

Fantastic: That fixed it!

Indeed, I am very pleased now as I have split my reference data (lists of teams and suppliers) out of the main body of data and have inserted these into the same XML file thus ...

<dataroot>
 <team>
  <teamdetails>
  ...
  </teamdetails>
 </team>
 <supplier>
  <supplierdetails>
  ...
  </supplierdetails>
 </supplier>
 <salesdata>
  <salesdatadetails>
  ...
  </salesdatadetails>
 </salesdata>
</dataroot>

I also stripped out any '0' values and replaced them with NULL so that they aren't exported to the XML file.

I found that this greatly reduced the size of the XML (i.e. descriptive information had been moved to the 'reference zones') and at the same time meant that I could use key() and generate-id() to do the grouping and summing on the file. I also reduced the length of field names which also helped reduce the size of the file.

With the reduced file size the response time also jumped from 50 secs to 5 secs.

I hope this posting will help others and am wondering if this is the correct way to do it? I hope so :-)

> I suspect there are other bugs in your code concerning context, but
> without a source document or real code, as distinct from fragments,
> I can't be sure.

Your probably right as I am still a bit shakey on the logic but think/hope it is coming now.

Many thanks for your help.

Regards,
Alan.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 PM
<bean:message key="PNR.INPUT"/> key has null value warsha_14 Struts 1 November 13th, 2006 07:26 AM
TAB KEY working together KEY PRESS event thomaz C# 4 August 20th, 2006 02:47 PM
Need xref Fix ~Bean~ SQL Language 2 October 5th, 2005 02:45 PM
Displaying Xref-Tables in Datagrid in VB.NET Ron Howerton VB.NET 2002/2003 Basics 0 December 15th, 2003 02:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.