xsl-list
[Top] [All Lists]

Re: Navigating XML Using Attributes

2003-02-11 15:20:33
Hi James,

To navigate the XML document, one must pull the Ids from element
<LevelA3> and return to the <Account> level to find the <LevelA3>
elements that reside in the document just below <Account>. Once the
appropriate <LevelA3> element is found, the XSL must find its way to
<LevelB2>, grab its Id, return to the top and find <LevelB2> below.
This continues until the data contained in <LevelC1> is found. For
example, the path to DataGamma is: Account/LevelA1/LevelA2/LevelA3
Id="333"/LevelB1/LevelB2 Id="11"/LevelC1:DataGamma

I assume I will have to use apply-templates again and again. What I
don't know is how to remember all the Ids in LevelA3, and below, so
I can find each of the cooresponding elements. Any suggestions?

I don't really understand the problem about *remembering* the Ids in
LevelA3. If you apply templates to all the LevelA3 elements then they
will all be processed. I'd have something like:

<xsl:template match="LevelA2">
  ...
  <xsl:apply-templates select="LevelA3" />
  ...
</xsl:template>

<xsl:template match="LevelA3">
  <xsl:variable name="id" select="@Id" />
  <xsl:apply-templates select="/Account/LevelA3[(_at_)Id = $id]" />
</xsl:template>

<xsl:template match="LevelA3[node()]">
  ...
</xsl:template>

I would also consider using a key to index the elements under the
Account element by their Id attributes (and possibly by their name) so
that you can access them quickly.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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



<Prev in Thread] Current Thread [Next in Thread>