xsl-list
[Top] [All Lists]

[xsl] How to properly use Key elements

2013-10-13 19:41:33
Hi,

I've read (and reread) Jeni Tenison's description of Muenchian Grouping several 
times and when my example is similar in structure to her example, I'm able to 
use it quite effectively but when my source XML varies from her example, I'm a 
bit lost.

I'm wondering if I can create a key to group on ShipName and/or RouteNum. As a 
complication, I don't knowing anything more than the fact that ShipName is a 
preceding sibling and that there will be 4 TD elements in rows that contain 
ShipName.

XML

<table>
        <tbody>
                <tr>
                        <td rowspan="6">ShipName</td>
                        <td rowspan="3">RouteNum</td>
                        <td>PortName</td>
                        <td>PortCode</td>
                </tr>
                <tr>
                        <td>PortName</td>
                        <td>PortCode</td>
                </tr>
                <tr>
                        <td>PortName</td>
                        <td>PortCode</td>
                </tr>
                <tr>
                        <td rowspan="3">RouteNum</td>
                        <td>PortName</td>
                        <td>PortCode</td>
                </tr>
                <tr>
                        <td>PortName</td>
                        <td>PortCode</td>
                </tr>
                <tr>
                        <td>PortName</td>
                        <td>PortCode</td>
                </tr>

                {… repeat rows …}

        </tbody>
</table>


My question is if I can "legally" define a KEY element like this:

<xsl:key 
        name="ports-by-ship" 
        match="td[position() = (count(.) - 1)]" 
        use="tr[count(td) = 4]/td[position() = 1]"
 />

The XSL spec says that "match" should be a "pattern" while "use" can be an 
"expression". I'm not exactly sure what they mean by expression, how it is 
different from a pattern match that uses a predicate.

I've been unable to get this to work but it sure would be handy if I could.

Thanks to anyone who can lend a hand. I've been off the list for years but 
recently found myself (happily) doing some more xslt.

Sincerely,

Ted Stresen-Reuter
--~------------------------------------------------------------------
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>