Subject: Re: [xsl] Matching Question From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Mon, 10 Jun 2002 09:01:53 +0100 |
Hi Michael, > I have a matching problem, probably somone can explain this to me. > Given this XML: > > <parent> > <child>foo bla</child> > <onemorechild>42</onemorechild> > </parent> > <parent> > ... > </parent> > > I want to match for all parent/onemorechild that have a specific > value, say 42, but then get the content of parent/child and this > match should fit in one <xsl:value-of />, is this possible? If the "match" should fit in a xsl:value-of, then it's not a "match" (pattern), it's a "select" (expression). You want to *select* the child element of the parent element whose onemorechild child element has the value '42'. To get the parent element whose onemorechild child has the value '42', use a predicate: parent[onemorechild = '42'] then step down from that parent element to the child child element: parent[onemorechild = '42']/child In an xsl:value-of: <xsl:value-of select="parent[onemorechild = '42']/child" /> There are other ways as well, for example: parent/onemorechild[. = '42']/preceding-sibling::child parent/onemorechild[. = '42']/../child parent/child[../onemorechild = '42'] but the above is probably simplest and visits least nodes. If you *know* that there is only one parent element whose onemorechild child element has the value '42', then you should probably use: parent[onemorechild = '42'][1]/child to help the processor optimise (it means that it can stop when it finds the suitable parent element, rather than going through all the rest of them). If you're picking out the child elements based on their sibling onemorechild elements' values a lot within the same stylesheet, then it might be worth constructing a key to index the child elements directly: <xsl:key name="children" match="child" use="../onemorechild" /> and then just using: key('children', '42') for example. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Matching Question, Michael Zehrer | Thread | [xsl] Mods and Looping, gary cor |
Re: [xsl] keys vs. parameters, Jeni Tennison | Date | RE: [xsl] James Clark on Schema, bryan |
Month |