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

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

Subject: Re: Is it possible in XSLT -- Please help us ....
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 11 Jul 2001 11:43:40 +0100
xslt xsl for each test
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@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
======================================================================


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.