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

Re: Can't get id() and key() to work

Subject: Re: Can't get id() and key() to work
From: Aaron Optimizer Digulla <digulla@xxxxxxxx>
Date: Sun, 8 Sep 2002 19:59:17 +0200
element get id
On Sun, Sep 08, 2002 at 06:43:37PM +0200, J.Pietschmann wrote:

> Aaron Optimizer Digulla wrote:
> >What I basically need is:
> >
> >    <xsl:variable name="infodoc" select="document('infodoc.xml')"/>
> >    <xsl:variable name="info" select="$infodoc/id($key)"/>
> >
> >ie. I have an XML document in $infodoc which has IDs and I want to
> >lookup elements in $infodoc.
> 
> The id() and key() functions work on the document which the
> current context  node is from. A standard technique to change
> the document is to use xsl:for-each:
>    <xsl:variable name="infodoc" select="document('infodoc.xml')"/>
>    <xsl:for-each select="$infodoc">
>      <xsl:variable name="info" select="id($key)"/>
>      ... do something with $info ...
>    </xsl:for-each>
> 
> >
> >I tried to use key() and it actually works but I can't use the
> >result:
> >
> >    <xsl:variable name="info-fragment">
> >	<xsl:for-each select="$imginfo">
> >	    <xsl:copy-of select="key('imgInfoKey', $path-key)"/>
> >	</xsl:for-each>
> >    </xsl:variable>
> ...
> >so apparently there is something in $info-fragment but what?
> 
> If you use xsl:variable without select, it will be an RTF (result
> tree fragment). A RTF has always exactly one root node, same like
> every XML document has. This is what causes the count()=1. OTOH,
> the root node never has any attribute, therefore
>  exslt:node-set($info-fragment)/@width
> is empty. You should try exslt:node-set($info-fragment)/*/@width
> or something replacing the * with the element name of one of the
> elements copied into the RTF.
Ahhh.... yes, when I do "exslt:node-set ($info-fragment)/*", then
it suddenly work!

And thanks to your explanation I suddenly understand what is
going on, too!

Thanks a lot!

> I suspect that "key didn't work", i.e. didn't select anything,
> because it tried to look up the key in the original document
> rather than the $infodoc document.

Err no, I had defined it the wrong way (mixed name and match,
used the wrong element in match and two more mistakes). After
finally understanding how it is supposed to work, I could fix
the mistakes and make it work :-)

-- 
==============================================
Sowatec AG,       CH-8330 Pfäffikon (ZH)
Witzbergstr. 7,   http://www.sowatec.com
Tel: +41-(0)1-952 55 55
Fax: +41-(0)1-952 55 66
----------------------------------------------
Aaron "Optimizer" Digulla, digulla@xxxxxxxxxxx
==============================================

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.