xsl-list
[Top] [All Lists]

RE: [xsl] Selecting the first node set

2006-08-05 04:53:58
Your question is a bit ambiguous. Is the node you want the first Value node in 
the document or is it the first Value node containing enum children with the 
content "A" and "B" and "C"?

If it is the latter, then this will give the result:

<xsl:template match="/">
  <xsl:apply-templates select="Trade/*/Value[1][enum = 'A'][enum = 'B'][enum = 
'C']" />
</xsl:template>
        
<xsl:template match="Value">
  <xsl:copy-of select="." />
</xsl:template>

If it is the former, then this will give the result:

<xsl:template match="/">
  <xsl:apply-templates select="Trade/*[1]/Value[1]" />
</xsl:template>
        
<xsl:template match="Value">
  <xsl:copy-of select="." />
</xsl:template>
-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Fraser Goffin <goffinf(_at_)hotmail(_dot_)com>
Sent:     Sat, 05 Aug 2006 12:21:58 +0100
To:       xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject:  [xsl] Selecting the first node set

Given the following simplified XML instance, can anyone suggest an 
expression that will return ONLY the 'Value' node containing <enum> children 
with values A, B and C. I can't rely on the name of the parent node of 
<Value> hence I have deliberately named these as UnknownNameX or any other 
intervening structure.

<Trade>
        <UnknownName1>
                <Value>
                        <enum>A</enum>
                        <enum>B</enum>
                        <enum>C</enum>
                </Value>
        </UnknownName1>
        <UnknownName2>
                <Value>/Trade//Value[ancestor::Trade]</Value>
        </UnknownName2>
        <Treatment>
                <UnknownName3>
                        <Value>
                                <enum>D</enum>
                                <enum>E</enum>
                                <enum>F</enum>
                        </Value>
                </UnknownName3>
        </Treatment>
</Trade>


/Trade//Value        - returns all 3 <Value> nodes
/Trade//Value[1]    - also returns all 3 <Value> nodes (why is that ?)
/Trade//Value[2]    - returns nothing (why is that ?)

Cheers

Fraser.



--~------------------------------------------------------------------
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>
--~--




--~------------------------------------------------------------------
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>
--~--