Subject: Re: [xsl] retrive data from #1 xml via data from #2 xml From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Thu, 15 Mar 2001 04:57:44 +0000 |
Hi Walter, > Does this need to be that exact? > > "/callEvent//interaction" this won't work? If you make it /callEvent//interaction then the xsl:for-each is cycling over every callEvent//interaction. That's fine (assuming that you have one row per interaction element), but the paths that you're giving within the @id attribute of the display elements are currently relative to its events/call_event grandchild - they point to its children - whereas in the code you're trying to find the element children of the current node (which would be an interaction element with the above path). So if you want to iterate over the interaction elements, then you can either change it so that the node that the column ids are resolved relative to are the events/call_event grandchildren of the interaction element with: <tr> <xsl:for-each select="$data"> <xsl:variable name="datum" select="events/call_event" /> <xsl:for-each select="$columns"> <xsl:variable name="column" select="." /> <td> <xsl:value-of select="$datum/*[name() = $column]" /> </td> </xsl:for-each> </xsl:for-each> </tr> [Note that this doesn't deal with the source/timestamp column.] Or you can change the paths so that they're all relative to the interaction element: <titles> <display id='source/timestamp' colWidth='104' sortOrder='D' defaultSort='T'>Date</display> <display id='events/call_event/curr_dest' colWidth='060' sortOrder='A' defaultSort='F'>Agent</display> <display id='events/call_event/media' colWidth='060' sortOrder='A' defaultSort='F'>Channel</display> <display id='events/call_event/reason' colWidth='120' sortOrder='A' defaultSort='F'>Reason</display> <display id='events/call_event/detailed_comment' colWidth='*' sortOrder='A' defaultSort='F'>Comments</display> </titles> and then use something like saxon:evaluate() to dynamically evaluate the paths: <tr> <xsl:for-each select="$data"> <xsl:variable name="datum" select="." /> <xsl:for-each select="$columns"> <xsl:variable name="column" select="." /> <td> <xsl:value-of select="saxon:evaluate(concat('$datum/', $column))" /> </td> </xsl:for-each> </xsl:for-each> </tr> >> Of course you can crop the path there depending on the context when >> you're setting the variable. > > "/callEvent//interaction" is this what you mean be 'cropping'? No, I meant cropping from the left so that the rest of the path is resolved relative to the current node. So for example if the current node when you set up the $data variable is the interaction_list element then you could make it: interaction/events/call_event >> That should then work, aside from the fact that one of the display >> element's id attributes has a value of 'source/timestamp'. That's not >> the name of any of the subelements of call_event... > > No, it's a subelement of 'interaction'. Yes. But my point was that in the code, you're doing: <xsl:value-of select="$datum/*[name() = $column]" /> This says: take the node that's held in the $datum variable (that's the interaction element in your case) and then go to the child element of that node whose name is the same as the column id. So to use this code you need to make sure that there *are* children of the interaction element whose name is that name. If there aren't, it won't find anything and won't give you any value. >> (and it can't be because it has a '/' in it). > > Right, the '/' makes its it subelement, not part of the NODE name. > > So I can't use this syntax? You *can* use this syntax, but it has no special meaning to a basic XSLT stylesheet. It is just a string as far as an XSLT processor is concerned. If you want to interpret it as a path, then you have to use something like saxon:evaluate() that evaluates a string as a path. >> If you're going to be using strange paths a lot in your table >> definitions,... > > 'strange paths'? is '/source/timestamp' a strange path? It's a perfectly fine path. It's just that (a) it's not relative to the same node as the rest of the paths in your display elements (they're relative to the call_event grandchild of the interaction element, not the interaction element itself) and (b) XPath syntax has no special relevance when it's a value in some XML. You might just as well be using 'source:timestamp' for all the XSLT processor cares. I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] retrive data from #1 xml , Walter Torres | Thread | [xsl] Re: retrieve data from #1 xml, Walter Torres |
Re: [xsl] transforming a XML to CS, Jeni Tennison | Date | Re: [xsl] Functional programming in, Jeni Tennison |
Month |