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

RE: xsl:key use attribute using string() causes missin

Subject: RE: xsl:key use attribute using string() causes missing all matches except the first one
From: <Yovanis@xxxxxxxxxxxx>
Date: Wed, 24 Mar 2004 12:06:22 -0500
xsl key sample
Hi!.
If you have this xml document:

<?xml version="1.0" encoding="UTF-8"?>
<Root>
	<elements>text1<element>text2</element>
		<element>text3</element>
	</elements>
</Root>

If you apply the function string() to the node "elements" the result is
"text1text2text3"

 string(//elements) = "text1text2text3"

Yov@nis

-----Original Message-----
From: Michael Kay [mailto:mhk@xxxxxxxxx] 
Sent: Wednesday, March 24, 2004 8:56 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  xsl:key use attribute using string() causes missing
all matches except the first one

When you apply string() to a node-set containing more than one node it
returns the string value of the first node in the node-set.

Michael Kay 

# -----Original Message-----
# From: Xiaocun Xu [mailto:xiaocunxu@xxxxxxxxx] 
# Sent: 24 March 2004 16:42
# To: xsl-list
# Subject:  xsl:key use attribute using string() causes 
# missing all matches except the first one
# 
# Hi,
# 
# I recently had an interesting discovery with xsl:key use 
# attribute using string().
# I been using string() in xsl:key use attribute extensively 
# since it allows me to retrieve records using the key value 
# "".  But in the following example, using string() caused me 
# to miss all matches except the first one.  I am not sure what 
# is the reason for this, would appreciate if anyone could shed 
# light on this behavior.  Example input XML and XSLT below.
# 
# thanks,
# Xiaocun
# 	
# input XML:
# <range>
# 	<row row="16">
# 		<cell column="1">supplier</cell>
# 		<cell column="2">s3</cell>
# 		<cell column="3">item</cell>
# 		<cell column="4">
# 			<subcell>item1</subcell>
# 			<subcell>item2</subcell>
# 			<subcell>item3</subcell>
# 		</cell>
# 		<cell column="5">s3_AM1</cell>
# 		<cell column="6">accepted</cell>
# 	</row>
# 	<row row="17">
# 		<cell column="1">supplier</cell>
# 		<cell column="2">s4</cell>
# 		<cell column="3">item</cell>
# 		<cell column="4">
# 			<subcell>item1</subcell>
# 			<subcell>item2</subcell>
# 			<subcell>item4</subcell>
# 		</cell>
# 		<cell column="5">s4_AM1</cell>
# 		<cell column="6">accepted</cell>
# 	</row>
# 	<row row="18">
# 		<cell column="1">supplier</cell>
# 		<cell column="2">s5</cell>
# 		<cell column="3">item</cell>
# 		<cell column="4">item1</cell>
# 		<cell column="5">s5_AM1</cell>
# 		<cell column="6">accepted</cell>
# 	</row>
# </range>
# 
# complete XSLT without using string():
# <xsl:stylesheet version="1.0"
# xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
# xmlns:fo="http://www.w3.org/1999/XSL/Format">
# <xsl:key name="itemInvitesKey"
# match="//row[cell[@column=3] = 'item']"
# use="cell[@column=4]"/>
# <xsl:key name="itemInvitesKey"
# match="//row[cell[@column=3] = 'item']"
# use="(cell[@column=4]/subcell)"/>
# <xsl:template match="/">
# 	<xsl:apply-templates select="range"/>
# </xsl:template>
# <xsl:template match="range">
# 	<xsl:text>item1&#xA;</xsl:text>
# 	<xsl:for-each select="key('itemInvitesKey', 'item1')">
# 		<xsl:value-of select="cell[@column=2]"/>
# 		<xsl:text>&#xA;</xsl:text>
# 	</xsl:for-each>
# 	<xsl:text>&#xA;</xsl:text>
# 	<xsl:text>item2&#xA;</xsl:text>
# 	<xsl:for-each select="key('itemInvitesKey', 'item2')">
# 		<xsl:value-of select="cell[@column=2]"/>
# 		<xsl:text>&#xA;</xsl:text>
# 	</xsl:for-each>
# </xsl:template>
# </xsl:stylesheet>
# 
# correct output:
# item1
# s5
# s3
# s4
# 
# item2
# s3
# s4
# 
# Exact same XSLT as above, except xsl:key use attribute using string():
# <xsl:key name="itemInvitesKey"
# match="//row[cell[@column=3] = 'item']"
# use="string(cell[@column=4]/subcell)"/>
# 
# Output: same as above, except no matches were returned except 
# for the first key (item1)
# item1
# s5
# s3
# s4
# 
# item2
# 
# __________________________________
# Do you Yahoo!?
# Yahoo! Finance Tax Center - File online. File on time.
# http://taxes.yahoo.com/filing.html
# 
# 
# 

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