|
Subject: Re: [xsl] Keys off of variable xml source From: Karl Stubsjoen <kstubs@xxxxxxxxx> Date: Fri, 1 Apr 2005 11:17:16 -0700 |
Thanks for all the effort here, the context of keys and how to use
them against external xml source is much clearer to me now. This (as
usual) was a very valuable lesson!
On Apr 1, 2005 10:08 AM, Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> wrote:
> Karl,
>
> At 11:24 AM 4/1/2005, you wrote:
> >The reason for a lookup xml source is to act as a cross-reference to
> >data in the main xml source. So, I need to reference all elements
> >who's ID = 123 but my match is expressed as a code value "abc". The
> >code "abc" maps to 123 in my lookup.
> >So, I'm still scratching my head wondering how I might effectively put
> >the external file to use with keys, but thinking it won't work, the
> >context would strictly be of the main xml source.
>
> source:
> <match code="abc"/>
>
> lookup:
> <code lookup="abc" value="123"/>
>
> in the stylesheet:
>
> <xsl:variable name="lookup" select="document('lookup.xml')"/>
>
> <xsl:variable name="codes" match="*" use="@lookup"/>
>
> <xsl:template match="match">
> <xsl:variable name="lookup-code" select="@code"/>
> <xsl:variable name="target-id">
> <xsl:for-each select="$lookup"/>
> <xsl:value-of select="key('codes',$lookup-code)/@value"/>
> </xsl:for-each>
> </xsl:variable>
> ... now the value '123' is available bound to $target-id
> (as an RTF, convertible to a string) ...
> </xsl:template>
>
> I hope that helps. It's a bit cumbersome in XSLT 1.0, but works well enough.
>
> Cheers,
> Wendell
>
> ======================================================================
> Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx
> Mulberry Technologies, Inc. http://www.mulberrytech.com
> 17 West Jefferson Street Direct Phone: 301/315-9635
> Suite 207 Phone: 301/315-9631
> Rockville, MD 20850 Fax: 301/315-8285
> ----------------------------------------------------------------------
> Mulberry Technologies: A Consultancy Specializing in SGML and XML
> ======================================================================
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Keys off of variable xml , Wendell Piez | Thread | RE: [xsl] Keys off of variable xml , Michael Kay |
| RE: [xsl] Testing 2 XML documents f, Mukul Gandhi | Date | RE: [xsl] Testing 2 XML documents f, Michael Kay |
| Month |