This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Is it possible in XSLT -- Please help us ....


Ramesh,

This is another natural use for keys. Funny how these things all happen at 
once: this is the third of fourth we've had in the last couple of days.

You want to retrieve hazmatlang nodes given a string value, namely the 
hazcode for any given hazmat.

(Hazmats are those things they don't let on the highway, right? :-)

So:

<xsl:key name="hzmlang-by-code" match="hazmatlang" use="hazcode"/>

The key is set to use the hazcode element child of any hazmatlang element 
to retrieve that element.

Then, in your template for hazmats:

<xsl:template match="hazmat">
     <xsl:variable name="matched-langs" select="key('hzmlang-by-code', 
hazcode)"/>
        <!-- The key retrieves any hazmatlang whose hazcode element
             is the same as the hazcode element of the hazmat
             (the second argument). Strictly speaking you don't need
             a local variable, but hey. -->
     <xsl:for-each test="$matched-langs">
             Process them here: you'll get all of them.
             Or you could use an apply-templates instead of
             the for-each, and process them in their own template. -->
     </xsl:for-each>
     <xsl:if test="not($matched-langs)">
        <!-- fallback processing for hazmats that have no
             matching hazmatlangs can go here -->
     </xsl:if>
   </xsl:choose>
</xsl:template>

This can also be done the long way with an XPath expression such as 
'//hazmatlang[hazcode=current()/hazcode]' but the key is a little cleaner 
and allows the processor to optimize retrieval. As someone just remarked 
yesterday, they also have the virtue of legibility once you learn how they 
work.

I hope that helps--
Wendell

At 01:16 AM 7/11/01, you wrote:
>Hi all,
>Please help us!!!
>
>We have two different nodesets (say for example hazmat and hazmatlang). 
>both can repeat n number of times in the same file.
>What we want to achieve is to compare hazmat nodesets with each of the 
>hazmatlang  nodeset for one of the common element (hazcode) to be of the 
>same value.
>
>1. If it matches then we must get the hazmatlang node values for the 
>matched node alone.
>
>2. If it not matches then we must print the hazmat node values alone.
>
>3.  We may have more number of hazmatlang node sets than the hazmat nodes. 
>We have to handle that also.
>
>Additional info.. If I may be wrong in explaining the node sets.
>Hazmat node sets -
><hazmat>
>  <hazcode>hc1</hazcode>
><otherproperties> ...</otherproperties>
></hazmat>
>...
>Hazmatlang node sets -
><hazmatlang>
>  <hazcode>hc1</hazcode>
>  <otherproperties> ...</otherproperties>
>  <additional other properties for lang> ...</additional other properties 
> for lang>
></hazmatlang>
>
>...
>
>Thanks in advance.
>Ramesh


======================================================================
Wendell Piez                            mailto:wapiez@mulberrytech.com
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
======================================================================


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]