[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:22 +0200
xsl value of select key
On Sun, Sep 08, 2002 at 10:02:56AM -0700, Robert Koberg wrote:

> Hi,
> 
> Assuming you have the key set up correctly you can simply match the 'image' tag
> from you source XML (example source would help). The source XML's image tag has
> the unique ID. For example:
> 
> <xsl:template match="image">
>   <xsl:for-each select="$infodoc">
>     <xsl:message>info2=<xsl:value-of select="$path-key"/></xsl:message>
>     <xsl:message>info3=<xsl:value-of select="key('imgInfoKey',
> $path-key)/@width"/></xsl:message>
>     <xsl:message>info4=<xsl:value-of select="key('imgInfoKey',
> $path-key)/@height"/></xsl:message>
>   </xsl:for-each>
> </xsl:template>
> 
> I try to avoid extensions. Do you really need them? If you can do without, then
> you need to get into the context of the document you need information from. Then
> use the key to find the nodeset and get the value you want from there. You
> cannot store the value of this nodeset in a variable. You need to use the key
> each time.
> 
> Does this help?

Yes, thank you.

As for not using extensions: I understand that using extensions makes
the stylesheet unportable.

BUT

I generate about 500 page with roughly 40 images in each of them.
I *have* to do the lookups as seldom as possible. That's why
I need to convert the RTF into a node-set and then work on
that.

I have now written an extension function which allows me to conveniently
call

    <xsl:variable name="info" select="my:lookup-image-info ($key)"/>

which is a) very readable, b) fast and c) exactly what I need.

(Portability is not an issue for me; xsltproc is available for all
systems where I need it).

But I hope that XSLT 2 solves these problems. It would really be
nice if one could pass the context into key() and id().

> > Hello,
> >
> > 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.
> >
> > 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>
> >     <xsl:message>info2=<xsl:value-of select="$path-key"/></xsl:message>
> >     <xsl:message>info3a=<xsl:value-of
> > select="exslt:object-type($info-fragment)"/></xsl:message>
> >     <xsl:message>info3b=<xsl:value-of
> > select="count($info-fragment)"/></xsl:message>
> >     <xsl:variable name="info" select="exslt:node-set($info-fragment)"/>
> >     <xsl:message>info4=<xsl:value-of select="$info/@width"/></xsl:message>
> >     <xsl:message>info4b=<xsl:value-of
> > select="exslt:node-set($info-fragment)/@width"/></xsl:message>
> >
> > This gives:
> >
> > info2=images/uy-online-left.jpg
> > info3a=RTF
> > info3b=1
> > info4=
> > info4b=
> >
> > so apparently there is something in $info-fragment but what?
> >
> > --
> > ==============================================
> > 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
> >
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 

-- 
==============================================
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.