xsl-list
[Top] [All Lists]

Re: [xsl] Fwd: xsl:key() and $variables.

2006-07-21 21:40:33
Hi Steve,

A lot of people, myself included, have limited time, and simply can not spend the time doing the research on your previous threads such that we can gain better context as to what you mean.

With this in mind, if you want to find a solution to your problem, please provide more detail. In this case, there is simply not enough information here to make sense of what you are attempting to do. For example,

How does the variable that contains Records/Record gain access to this data? Is it an external XML document accessed via the document function? At first site, it seems as if your suggesting that the variable contains this XML data embedded directly inside of the opening and closing tag. Is this the case? If yes, are you using an XSLT 1.0 or XSLT 2.0 processor?

This is an important point to consider, as you may very well be stuck at a point that you didn't even realize existed, dealing with Result Tree Fragments that limit the operations that can be performed, without first being converted to a node-set. Unfortunately, converting an RTF to a node-set requires an external function, as this is not something that was a part of the XSLT 1.0 spec.

Setting this aside, lets assume that the Records/Record data set is an external document accessed via the document function. We know that the second set of XML, blah.xml, is an external document accessed via the document function. Whats missing now is understanding where this XML data is now stored such that we can use this as a point of reference for comparing with the Records/Record data-set.

With this information, we can then gain a better understanding as to how to properly process each XML data-set, using the distinct values of one data-set to compare against the other, and filter the result set based on a filtered criteria.

If I were to make an educated guess, it seems in this case you are desirous to obtain from the Records/Record/activity data-set, those 'activity' elements in which contains a text node who's string value is equal to the string value of the text node contained between the opening and closing activity element of the second data-set in which contains an attribute who's name is 'neccesary' and whos value is equal to = 'yes'.

In other words, you want to create an index with the second data set of only those elements in which contain a necessary attribute = 'yes'.

[From your sample]
<activity neccesary="yes">Writing</activity>

would be the only element that matches this criteria, although in the actual data there are probably others as well.

None-the-less,

With the above index, you now want to parse through the first data set, and locate elements that contain the same string value, in this case 'Writing', outputting the result of this processing.

Is this correct?

If yes, then lets make sure you are operating on data that is a proper node-set instead of a RTF first, and move forward into understanding how to use keys to properly group and filter your data.

Steve wrote:

---------- Forwarded message ----------
From: Steve <subsume(_at_)gmail(_dot_)com>
Date: Jul 20, 2006 3:41 PM
Subject: xsl:key() and $variables.
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com


I have a variable containing

<Records>
  <Record>
     <activity>Baseball</
     <hours>36</
  <Record>
     <activity>Shopping</
     <hours>39</
  <Record>
     <activity>Writing</
     <hours>3</
   ......etc  (yes, I know they're not closed.)

and some xml (document('../blah.xml') containing...

<activities>
   <activity neccesary="no">Baseball</
   <activity neccesary="no">Shopping</
   <activity neccesary="yes">Writing</

..............

How do I  <xsl:apply-templates select="$variable/Records/Record[1]" />
only those records which are neccesary="yes"  ?

I swear one of these posts I'll have xsl:key figured out.

-Steve

--
/M:D

M. David Peterson
http://mdavid.name | http://www.oreillynet.com/pub/au/2354 <http://www.oreillynet.com/pub/au/2354>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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