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

RE: equivalent for 'while'

Subject: RE: equivalent for 'while'
From: "Ross, Douglas" <DRoss@xxxxxxxxxx>
Date: Wed, 16 Feb 2005 14:24:11 -0500
for while
How do I find the grandchild'th element?

The original XML is like:

<dc id="parent">
	<child ref="child"/>
</dc>
<dc id="child">
	<child ref="grandchild"/>
</dc>
<dc id="grandchild"/>

Could be expressed as:

<dc id="parent">
	<dc id="child">
		<dc id="grandchild"/>
	</dc>
</dc>

In the later XML, I would match /dc/dc/dc to get the grand child. But
how would I match in the former XML?

I wonder if the following psudo-xslt works?

1) Create an index of all the child elements on the ref attribute (using
keys), for example, <xsl:key name="t" match="child" use="@ref" />

2) Create a template to match each dc element. Inside the match
template, use the child node's ref attribute to find the child dc
element in the index. Then get it's child ref id to find the grandchild
dc element in the index. For example,
<xsl:template match="dc">
	<xsl:variable name="child" select="key('t', child/@ref)"/>
	<xsl:variable name="grandchild" select="key('t',
$child/child/@ref)"/>
	<!-- do something with $grandchild -->
</xsl:template>

You could even use a recursive template call to do this to a specific
level of children.

Douglas Ross
Developer, HTML UI Framework
Kronos
E-mail: dross@xxxxxxxxxx
Voice: (978) 947-4305
Fax: (978) 256-2474
www.kronos.com
Smaller, Faster, Sharper, Easier(tm)

-----Original Message-----
From: Richard Lewis [mailto:richardlewis@xxxxxxxxxxxxxx]
Sent: Wednesday, February 16, 2005 12:30 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  equivalent for 'while'


On Wed, 16 Feb 2005 17:24:16 +0000, "RQamar" <qamar_rahil@xxxxxxxxxxx>
said:
> David Carlisle wrote:
>
>
> >>>>Is there an equivalent of 'while' loop in XSLT 2.0?
> >>>>
> >>>>
> >>
> >>
> >>
> >>it depends what you mean by equivalence.
> >>
> >>
> >
> >
>
>
> Well I have an XML document which has several <DEFCONCEPT> elements.
> Each of these elements contain certain <CHILD> sub-elements of the
form
> below:
>
> <DEFCONCEPT id="123" name="abc">
>     <CHILD ref="567">abcChild</CHILD>
> </DEFCONCEPT>
>
> <DEFCONCEPT id="567" name="abcChild">
>     <CHILD ref="890">abcGrandChild</CHILD>
> </DEFCONCEPT>
>
> <DEFCONCEPT id="890" name="abcGrandChild"/>
>
> How could I then place conditions when processing this XML doc such
that
> it continues searching for a <CHILD> element until it finds
> 'abcGrandChild' ?
>
> I thought perhaps a single statement could loop until the condition
> becomes 'true' which is obviously not in lines with declarative
> programming. How else is it then possible?
>
Does
<xsl:template match="child[text()='abcGrandChild']">
work?
Richard

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.