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

Use of xsl:key to perform node traversal according to

Subject: Use of xsl:key to perform node traversal according to an association between nodes
From: "Dunk, Michael (Mike)" <mikedunk@xxxxxxxxxxxxx>
Date: Wed, 26 Sep 2007 09:14:33 -0500
 Use of xsl:key to perform node traversal according to
Thank you to Michael Kay and Wendell Piez for their help with processing
context and paths.

George Cristian Bina your comments about namespaces were appreciated.

I am struggling to find any clues in the examples of xsl:key in the text
xslt books about to use xsl:key to retrieve the contents of an element.
Or as Wendell Piez described it "the use of a key to perform node
traversal according to an association between nodes". Here is an
simplified example of the type of xml input I need to read:

<?xml version="1.0" encoding="UTF-8"?>
    <Team name="Man Utd">



    <Player id="{0EA17FA0-D21B-4F1E-8B11-A250A6CF266C}+00000000"
name="Gary Neville"></Player>
    <Player id="{1F3E974C-F180-45EB-AB59-4D1ACF4BB855}+00000000"
name="Louis Saha"></Player>
    <Player id="{3F9BEEE0-35DB-4835-A89E-F2B240EC2CB0}+00000000"
name="Ryan Giggs"></Player>

The xslt written to list the teams and players is :

<?xml version='1.0'?>
<xsl:stylesheet version="2.0"
<xsl:output method="xml"/>

<xsl:key name="player-id" match="Teams_and_Players/Players/Player"

<xsl:template match="/">
  <xsl:apply-templates select="Teams_and_Players"/>

<xsl:template match="Teams_and_Players">
  <xsl:apply-templates select="Teams"/>

<xsl:template match="Teams">
  <xsl:apply-templates select="Team"/>

<xsl:template match="Team">
  <xsl:value-of select="@name"/>
  <xsl:apply-templates select="TeamPlayer"/>

<xsl:template match="TeamPlayer">
  <xsl:value-of select="key('player-id', @id)"/>

Currently the following is output:

<?xml version="1.0" encoding="UTF-8"?>
  <Team>Man Utd

Has anyone got any clues about what is wrong with?

<xsl:key name="player-id" match="Teams_and_Players/Players/Player"


<xsl:value-of select="key('player-id', @id)"/>

Best regards,


This email and any files transmitted with it are confidential, proprietary
and intended solely for the individual or entity to whom they are addressed.
If you have received this email in error please delete it immediately.

Current Thread


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.
First Name
Last Name
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-2013 All Rights Reserved.