Specify an element in a nodeset directly

Discussion in 'XML' started by eric.goforth@gmail.com, Oct 2, 2006.

  1. Guest

    Hello,

    Is there any way to directly access an element in a nodeset?

    For example, if working with:

    <blahs rec_count="16">
    <blah>
    <yada>abc</yada>
    </blah>
    <blah>
    <yada>123</yada>
    </blah>
    <blah>
    <yada>xyz</yada>
    </blah>
    </blahs>

    For instance, I could specify something like blahs/blah[2]/yada and get
    the value of "123"?

    -Eric
    , Oct 2, 2006
    #1
    1. Advertising

  2. Peter Flynn Guest

    wrote:
    > Hello,
    >
    > Is there any way to directly access an element in a nodeset?
    >
    > For example, if working with:
    >
    > <blahs rec_count="16">
    > <blah>
    > <yada>abc</yada>
    > </blah>
    > <blah>
    > <yada>123</yada>
    > </blah>
    > <blah>
    > <yada>xyz</yada>
    > </blah>
    > </blahs>
    >
    > For instance, I could specify something like blahs/blah[2]/yada and get
    > the value of "123"?


    Yes, exactly that. In XSLT, for example, you would write

    <xsl:value-of select="blahs/blah[2]/yada"/>

    But this doesn't have anything to do with nodesets.
    It's just an XPath statement referencing an element.

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/
    Peter Flynn, Oct 2, 2006
    #2
    1. Advertising

  3. Guest

    Peter Flynn wrote:
    > wrote:
    > > Hello,
    > >
    > > Is there any way to directly access an element in a nodeset?
    > >
    > > For example, if working with:
    > >
    > > <blahs rec_count="16">
    > > <blah>
    > > <yada>abc</yada>
    > > </blah>
    > > <blah>
    > > <yada>123</yada>
    > > </blah>
    > > <blah>
    > > <yada>xyz</yada>
    > > </blah>
    > > </blahs>
    > >
    > > For instance, I could specify something like blahs/blah[2]/yada and get
    > > the value of "123"?

    >
    > Yes, exactly that. In XSLT, for example, you would write
    >
    > <xsl:value-of select="blahs/blah[2]/yada"/>
    >
    > But this doesn't have anything to do with nodesets.
    > It's just an XPath statement referencing an element.
    >


    Peter,

    Hmmm, well the situation in a little more detail is that I'm passing in
    this nodeset, I believe that's the right word, in a parameter.

    So my entire XML document looks more like:

    <mydoc>
    <mystuff>
    <blahs rec_count="3">
    <blah>
    <yada>abc</yada>
    </blah>
    <blah>
    <yada>123</yada>
    </blah>
    <blah>
    <yada>xyz</yada>
    </blah>
    </blahs>
    </mystuff>
    </mydoc>

    I'm passing the blahs to a template as a parameter like so:


    <xsl:apply-templates select="somestuff">
    <xsl:with-param name="myblahs"
    select="/mydoc/mystuff/blahs"></xsl:with-param>
    </xsl:apply-templates>


    Then in my template it looks something like:

    <xsl:template match="somestuff">

    <xsl:param name="myblahs"/>

    .... Do some stuff...

    </xsl:template >

    So debugging the transformation of the somestuff template in XML Spy,
    if I look at $myblahs in the XPath-Watch, I see NodeSet[1]. If I click
    on the NodeSet[1] beside the $myblahs in the XPath-Watch I see blahs
    with a rec_count="3", so my data made it inside the somestuff template.

    However, if I do a <xsl:value-of select="$myblahs/blah[2]/yada"/>

    I get an Error: Invalid XPath.

    Thanks,
    Eric
    , Oct 2, 2006
    #3
  4. > However, if I do a <xsl:value-of select="$myblahs/blah[2]/yada"/>

    Try:

    $myblahs[2]/yada


    Cheers,
    Dimitre Novatchev

    <> wrote in message
    news:...
    >
    > Peter Flynn wrote:
    >> wrote:
    >> > Hello,
    >> >
    >> > Is there any way to directly access an element in a nodeset?
    >> >
    >> > For example, if working with:
    >> >
    >> > <blahs rec_count="16">
    >> > <blah>
    >> > <yada>abc</yada>
    >> > </blah>
    >> > <blah>
    >> > <yada>123</yada>
    >> > </blah>
    >> > <blah>
    >> > <yada>xyz</yada>
    >> > </blah>
    >> > </blahs>
    >> >
    >> > For instance, I could specify something like blahs/blah[2]/yada and get
    >> > the value of "123"?

    >>
    >> Yes, exactly that. In XSLT, for example, you would write
    >>
    >> <xsl:value-of select="blahs/blah[2]/yada"/>
    >>
    >> But this doesn't have anything to do with nodesets.
    >> It's just an XPath statement referencing an element.
    >>

    >
    > Peter,
    >
    > Hmmm, well the situation in a little more detail is that I'm passing in
    > this nodeset, I believe that's the right word, in a parameter.
    >
    > So my entire XML document looks more like:
    >
    > <mydoc>
    > <mystuff>
    > <blahs rec_count="3">
    > <blah>
    > <yada>abc</yada>
    > </blah>
    > <blah>
    > <yada>123</yada>
    > </blah>
    > <blah>
    > <yada>xyz</yada>
    > </blah>
    > </blahs>
    > </mystuff>
    > </mydoc>
    >
    > I'm passing the blahs to a template as a parameter like so:
    >
    >
    > <xsl:apply-templates select="somestuff">
    > <xsl:with-param name="myblahs"
    > select="/mydoc/mystuff/blahs"></xsl:with-param>
    > </xsl:apply-templates>
    >
    >
    > Then in my template it looks something like:
    >
    > <xsl:template match="somestuff">
    >
    > <xsl:param name="myblahs"/>
    >
    > ... Do some stuff...
    >
    > </xsl:template >
    >
    > So debugging the transformation of the somestuff template in XML Spy,
    > if I look at $myblahs in the XPath-Watch, I see NodeSet[1]. If I click
    > on the NodeSet[1] beside the $myblahs in the XPath-Watch I see blahs
    > with a rec_count="3", so my data made it inside the somestuff template.
    >
    > However, if I do a <xsl:value-of select="$myblahs/blah[2]/yada"/>
    >
    > I get an Error: Invalid XPath.
    >
    > Thanks,
    > Eric
    >
    Dimitre Novatchev, Oct 3, 2006
    #4
  5. Guest

    Dimitre Novatchev wrote:
    > > However, if I do a <xsl:value-of select="$myblahs/blah[2]/yada"/>

    >
    > Try:
    >
    > $myblahs[2]/yada
    >
    >
    > Cheers,
    > Dimitre Novatchev
    >
    > <> wrote in message
    > news:...
    > >
    > > Peter Flynn wrote:
    > >> wrote:
    > >> > Hello,
    > >> >
    > >> > Is there any way to directly access an element in a nodeset?
    > >> >
    > >> > For example, if working with:
    > >> >
    > >> > <blahs rec_count="16">
    > >> > <blah>
    > >> > <yada>abc</yada>
    > >> > </blah>
    > >> > <blah>
    > >> > <yada>123</yada>
    > >> > </blah>
    > >> > <blah>
    > >> > <yada>xyz</yada>
    > >> > </blah>
    > >> > </blahs>
    > >> >
    > >> > For instance, I could specify something like blahs/blah[2]/yada and get
    > >> > the value of "123"?
    > >>
    > >> Yes, exactly that. In XSLT, for example, you would write
    > >>
    > >> <xsl:value-of select="blahs/blah[2]/yada"/>
    > >>
    > >> But this doesn't have anything to do with nodesets.
    > >> It's just an XPath statement referencing an element.
    > >>

    > >
    > > Peter,
    > >
    > > Hmmm, well the situation in a little more detail is that I'm passing in
    > > this nodeset, I believe that's the right word, in a parameter.
    > >
    > > So my entire XML document looks more like:
    > >
    > > <mydoc>
    > > <mystuff>
    > > <blahs rec_count="3">
    > > <blah>
    > > <yada>abc</yada>
    > > </blah>
    > > <blah>
    > > <yada>123</yada>
    > > </blah>
    > > <blah>
    > > <yada>xyz</yada>
    > > </blah>
    > > </blahs>
    > > </mystuff>
    > > </mydoc>
    > >
    > > I'm passing the blahs to a template as a parameter like so:
    > >
    > >
    > > <xsl:apply-templates select="somestuff">
    > > <xsl:with-param name="myblahs"
    > > select="/mydoc/mystuff/blahs"></xsl:with-param>
    > > </xsl:apply-templates>
    > >
    > >
    > > Then in my template it looks something like:
    > >
    > > <xsl:template match="somestuff">
    > >
    > > <xsl:param name="myblahs"/>
    > >
    > > ... Do some stuff...
    > >
    > > </xsl:template >
    > >
    > > So debugging the transformation of the somestuff template in XML Spy,
    > > if I look at $myblahs in the XPath-Watch, I see NodeSet[1]. If I click
    > > on the NodeSet[1] beside the $myblahs in the XPath-Watch I see blahs
    > > with a rec_count="3", so my data made it inside the somestuff template.
    > >
    > > However, if I do a <xsl:value-of select="$myblahs/blah[2]/yada"/>
    > >
    > > I get an Error: Invalid XPath.
    > >
    > > Thanks,
    > > Eric
    > >


    I've figured out how to do get it to work. <xsl:value-of
    select="$myblahs/blah[2]/yada"/> is working for me now, I think that I
    must have had a type in there.

    The only problem I'm having now is figuring out how to make the "2"
    variable.

    For instance:

    <xsl:value-of
    select="$myblahs/blah[/xpath1/xpath2/someintegervalue]/yada"/>

    -Eric
    , Oct 3, 2006
    #5
  6. wrote:


    > <xsl:value-of
    > select="$myblahs/blah[/xpath1/xpath2/someintegervalue]/yada"/>


    $myblahs/blah[/xpath1/xpath2/someintegervalue = position()]/yada

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Oct 3, 2006
    #6
  7. Guest

    Martin Honnen wrote:
    > wrote:
    >
    >
    > > <xsl:value-of
    > > select="$myblahs/blah[/xpath1/xpath2/someintegervalue]/yada"/>

    >
    > $myblahs/blah[/xpath1/xpath2/someintegervalue = position()]/yada
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/


    Martin,

    Hmmm, that's not working for me. If I put in a "1" or a "2" it works,
    but not with the "variable".

    In my case

    <xsl:apply-templates select="thingsummary">
    <xsl:with-param name="furballs"
    select="/xpath1/xpath2/furballssummary"></xsl:with-param>
    </xsl:apply-templates>

    </xsl:template>

    <xsl:template match="thingsummary">

    <xsl:param name="furballs"/>

    <xsl:apply-templates select="thing[(position() mod 2)=1]">
    <xsl:with-param name="furballs"
    select="$furballs"></xsl:with-param>
    </xsl:apply-templates>

    </xsl:template>

    <xsl:template match="thing[(position() mod 2)=1]">

    <xsl:param name="furballs"/>

    <!-- This works-->
    <xsl:value-of select="thingintegerfield1"/>

    <!-- This works-->
    <xsl:value-of select="$furballs/furball[1]/furballmember"/>

    <!-- This works-->
    <xsl:value-of select="$furballs/furball[1=
    position()]/furballmember"/>

    <!-- This does not work-->
    <xsl:value-of
    select="$furballs/furball[1=thingintegerfield1]/furballmember"/>

    </xsl:template>

    Thanks
    Eric
    , Oct 3, 2006
    #7
  8. roy axenov Guest

    wrote:
    > Martin Honnen wrote:
    > > wrote:
    > > > <xsl:value-of select="
    > > > $myblahs/blah[/xpath1/xpath2/someintegervalue]/yada
    > > > "/>

    > >
    > > $myblahs/blah
    > > [/xpath1/xpath2/someintegervalue=position()]/yada

    >
    > Hmmm, that's not working for me. If I put in a "1" or a
    > "2" it works, but not with the "variable".


    Your example is awfully vague. For better results, provide
    a sample XML and a minimum XSLT demonstrating your problem.

    > <xsl:template match="thing[(position() mod 2)=1]">
    > <xsl:param name="furballs"/>
    > <!-- This works-->
    > <xsl:value-of select="thingintegerfield1"/>
    > <!-- This does not work-->
    > <xsl:value-of select="
    > $furballs/furball[1=thingintegerfield1]/furballmember
    > "/>
    > </xsl:template>


    First of all, the [1=thingintegerfield1] predicate should
    be [position()=thingintegerfield1] if I understood
    correctly what you're trying to do (it's hard to be sure
    without a working example).

    Even then, I'd say you don't understand how contexts work.
    Let's assume this template matched the node
    /foo[1]/bar[1]/thing[1]. What does thingintegerfield1 in
    the XPath marked as 'This works' refer to then? The answer
    is '/foo[1]/bar[1]/thing[1]/thingintegerfield1'. And what
    does thingintegerfield1 in the XPath marked as 'This does
    not work' refer to? '$furballs/furball/thingintegerfield1'.
    What you probably need is current()/thingintegerfield1,
    although, once again, it's hard to be sure without a
    working example.

    To demonstrate:

    XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <foo>
    <bar>
    <xyzzy>
    <int>3</int>
    </xyzzy>
    </bar>
    <nodeset>
    <node>
    <str>wrong (1)</str>
    <int>3</int>
    </node>
    <node>
    <str>wrong (2)</str>
    <int>2</int>
    </node>
    <node>
    <str>right (3)</str>
    <int>1</int>
    </node>
    </nodeset>
    </foo>

    XSLT:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="text"/>
    <xsl:template match="/">
    <xsl:apply-templates select="descendant::xyzzy">
    <xsl:with-param name="ns" select="/foo/nodeset"/>
    </xsl:apply-templates>
    </xsl:template>
    <xsl:template match="/foo/bar/xyzzy">
    <xsl:param name="ns"/>
    My Int: <xsl:value-of select="int"/>
    Wrong: <xsl:value-of select="
    $ns/node[int=position()]/str"/>
    Right: <xsl:value-of select="
    $ns/node[current()/int=position()]/str"/>
    </xsl:template>
    </xsl:stylesheet>

    --
    roy axenov
    roy axenov, Oct 3, 2006
    #8
  9. Guest

    roy axenov wrote:
    > wrote:
    > > Martin Honnen wrote:
    > > > wrote:
    > > > > <xsl:value-of select="
    > > > > $myblahs/blah[/xpath1/xpath2/someintegervalue]/yada
    > > > > "/>
    > > >
    > > > $myblahs/blah
    > > > [/xpath1/xpath2/someintegervalue=position()]/yada

    > >
    > > Hmmm, that's not working for me. If I put in a "1" or a
    > > "2" it works, but not with the "variable".

    >
    > Your example is awfully vague. For better results, provide
    > a sample XML and a minimum XSLT demonstrating your problem.
    >


    Roy,

    Here's an example of what I'm referring to. The "does not work"
    comment shows what I'm trying to do. The "this does work" shows where
    I'm able to hit the nodeset by hardcoding the parameter.

    Thanks,
    Eric

    <page>
    <contents>
    <ratessummary rec_count="3">
    <rate>
    <ratecode>1</ratecode>
    <myrate>1.1</myrate>
    </rate>
    <rate>
    <ratecode>2</ratecode>
    <myrate>1.2</myrate>
    </rate>
    <rate>
    <ratecode>3</ratecode>
    <myrate>1.3</myrate>
    </rate>
    </ratessummary>
    <thingsummary rec_count="3">
    <thing>
    <short_description>Jim</short_description>
    <description>James</description>
    <thingcode>1</thingcode>
    </thing>
    <thing>
    <short_description>Rick</short_description>
    <description>Richard</description>
    <thingcode>2</thingcode>
    </thing>
    <thing>
    <short_description>Fred</short_description>
    <description>Frederick</description>
    <thingcode>3</thingcode>
    </thing>
    </thingsummary>
    </contents>
    </page>

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">
    <xsl:template match="/">
    <html>
    <head></head>
    <body>
    <xsl:apply-templates select="page/contents"></xsl:apply-templates>
    </body>
    </html>
    </xsl:template>
    <xsl:template match="contents">
    <table>
    <tr>
    <td class="data">
    <xsl:apply-templates select="thingsummary">
    <xsl:with-param name="rates"
    select="/page/contents/ratessummary"></xsl:with-param>
    </xsl:apply-templates>
    </td>
    </tr>
    </table>
    </xsl:template>

    <xsl:template match="thingsummary">

    <xsl:param name="rates"/>

    <xsl:value-of select="$rates/rate[1]/org_id"/>

    <table>
    <xsl:apply-templates select="thing[(position() mod 2)=1]">
    <xsl:with-param name="rates" select="$rates"></xsl:with-param>
    </xsl:apply-templates>
    </table>
    </xsl:template>

    <xsl:template match="thing[(position() mod 2)=1]">
    <xsl:param name="rates"/>
    <tr>
    <td>
    <xsl:value-of select="short_description"/>-<xsl:value-of
    select="thingcode"/>-<xsl:value-of select="$rates/rate[1]/org_id"/>
    <!-- This does not work-->
    test1<xsl:value-of select="$rates/rate[position()=thingcode
    ]/myrate"/>
    <!-- This works-->
    test2<xsl:value-of select="$rates/rate[position()=1]/myrate"/>
    </td>
    <xsl:apply-templates select="following-sibling::thing[1]">
    <xsl:with-param name="rates" select="$rates"></xsl:with-param>
    </xsl:apply-templates>
    </tr>
    </xsl:template>
    <xsl:template match="thing[(position() mod 2)=0]">
    <xsl:param name="rates"/>
    <td>
    <xsl:value-of select="short_description"/>-<xsl:value-of
    select="thingcode"/><xsl:value-of select="$rates/rate[1]/org_id"/>
    <!-- This does not work-->
    test1<xsl:value-of select="$rates/rate[position()=thingcode
    ]/myrate"/>
    <!-- This works-->
    test2<xsl:value-of select="$rates/rate[1]/myrate"/>
    </td>
    </xsl:template>

    </xsl:stylesheet>
    , Oct 3, 2006
    #9
  10. roy axenov Guest

    wrote:
    > roy axenov wrote:
    > > wrote:
    > > > Martin Honnen wrote:
    > > > > wrote:
    > > > > > <xsl:value-of select="
    > > > > > $myblahs/blah
    > > > > > [/xpath1/xpath2/someintegervalue]/yada
    > > > > > "/>
    > > > >
    > > > > $myblahs/blah
    > > > > [/xpath1/xpath2/someintegervalue=position()]/yada
    > > >
    > > > Hmmm, that's not working for me. If I put in a "1" or
    > > > a "2" it works, but not with the "variable".

    > >
    > > Your example is awfully vague. For better results,
    > > provide a sample XML and a minimum XSLT demonstrating
    > > your problem.

    >
    > Here's an example of what I'm referring to. The "does
    > not work" comment shows what I'm trying to do. The "this
    > does work" shows where I'm able to hit the nodeset by
    > hardcoding the parameter.


    You should've read the rest of my post. Your example
    confirms that my initial guess was right on money. I ran a
    quick test, and the solution I proposed works, too.

    > <page>
    > <contents>
    > <ratessummary rec_count="3">
    > <rate>
    > <ratecode>1</ratecode>
    > <myrate>1.1</myrate>
    > </rate>
    > <rate>
    > <ratecode>2</ratecode>
    > <myrate>1.2</myrate>
    > </rate>
    > <rate>
    > <ratecode>3</ratecode>
    > <myrate>1.3</myrate>
    > </rate>
    > </ratessummary>
    > <thingsummary rec_count="3">
    > <thing>
    > <short_description>Jim</short_description>
    > <description>James</description>
    > <thingcode>1</thingcode>
    > </thing>
    > <thing>
    > <short_description>Rick</short_description>
    > <description>Richard</description>
    > <thingcode>2</thingcode>
    > </thing>
    > <thing>
    > <short_description>Fred</short_description>
    > <description>Frederick</description>
    > <thingcode>3</thingcode>
    > </thing>
    > </thingsummary>
    > </contents>
    > </page>


    [XSLT]

    > <xsl:apply-templates select="thingsummary">
    > <xsl:with-param name="rates"
    > select="/page/contents/ratessummary"></xsl:with-param>
    > </xsl:apply-templates>


    .. . .

    > <!-- This does not work-->
    > test1<xsl:value-of
    > select="$rates/rate[position()=thingcode]/myrate"/>


    So what does it do?

    $rates/rate selects a nodeset of <rate> nodes. The
    predicate [position()=thingcode] filters this nodeset,
    dropping all the nodes that don't have a <thingcode> child
    with content that is equal to the position of the <rate>
    node in the $rates/rate nodeset. Since there are no <rate>
    nodes with <thingcode> children in your document, the
    resulting nodeset is, naturally, empty. I already explained
    the solution in my previous reply.

    --
    roy axenov
    roy axenov, Oct 4, 2006
    #10
  11. Guest

    roy axenov wrote:

    > So what does it do?
    >
    > $rates/rate selects a nodeset of <rate> nodes. The
    > predicate [position()=thingcode] filters this nodeset,
    > dropping all the nodes that don't have a <thingcode> child
    > with content that is equal to the position of the <rate>
    > node in the $rates/rate nodeset. Since there are no <rate>
    > nodes with <thingcode> children in your document, the
    > resulting nodeset is, naturally, empty. I already explained
    > the solution in my previous reply.
    >
    > --
    > roy axenov


    Roy,

    I played around with your example, but it doesn't seem to work when I
    have multiple xyzzy elements, for example:

    <foo>
    <bar>
    <xyzzy>
    <int>3</int>
    </xyzzy>
    <xyzzy>
    <int>4</int>
    </xyzzy>
    <xyzzy>
    <int>5</int>
    </xyzzy>
    </bar>
    <nodeset>
    <node>
    <str>wrong (1)</str>
    <int>3</int>
    </node>
    <node>
    <str>wrong (2)</str>
    <int>2</int>
    </node>
    <node>
    <str>right (3)</str>
    <int>1</int>
    </node>
    </nodeset>
    </foo>

    I'm wondering if it's not possible to do what I'm trying to do.

    -Eric
    , Oct 5, 2006
    #11
  12. It really doesn't help us help you when you keep switching element
    names, so we can't easily run your new example against your previous
    description of the problem. Either pick one set and stick with it, or
    post the matched set of sample and failing stylesheet code.
    Joe Kesselman, Oct 6, 2006
    #12
  13. Your problem is that
    $rates/rate[position()=thingcode]/myrate
    is looking for a thingcode child of rate -- but of course the thingcode
    is child of thing. You're crossing contexts.

    The easy way around this is a variable:

    <td>
    <xsl:value-of select="short_description"/>-<xsl:value-of
    select="thingcode"/>-<xsl:value-of select="$rates/rate[1]/org_id"/>
    <!-- This does not work because rate has no thingcode-->
    test1<xsl:value-of
    select="$rates/rate[position()=thingcode]/myrate"/>
    <!-- This works-->
    test2<xsl:value-of select="$rates/rate[position()=1]/myrate"/>
    <!-- This works because we're asking for thingcode in the right
    context-->
    <xsl:variable name="code" select="thingcode"/>
    test3<xsl:value-of select="$rates/rate[position()=$code]/myrate"/>
    </td>



    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Oct 6, 2006
    #13
  14. Joe Kesselman wrote:
    > The easy way around this is a variable:


    The other way around it would be to say
    > test3<xsl:value-of
    > select="$rates/rate[position()=current()/thingcode]/myrate"/>


    which says explicitly that you want the thingcode child of the current
    XSLT context node (the thing) rather than the context at this point in
    the XPath.

    The good thing about computers is that they do what you tell them to.
    The bad thing about computers is that they do what you tell them to.

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Oct 6, 2006
    #14
  15. roy axenov Guest

    wrote:
    > roy axenov wrote:
    > > So what does it do?
    > >
    > > $rates/rate selects a nodeset of <rate> nodes. The
    > > predicate [position()=thingcode] filters this nodeset,
    > > dropping all the nodes that don't have a <thingcode>
    > > child with content that is equal to the position of the
    > > <rate> node in the $rates/rate nodeset. Since there are
    > > no <rate> nodes with <thingcode> children in your
    > > document, the resulting nodeset is, naturally, empty. I
    > > already explained the solution in my previous reply.

    >
    > I played around with your example, but it doesn't seem to
    > work when I have multiple xyzzy elements, for example:
    >
    > <foo>
    > <bar>
    > <xyzzy>
    > <int>3</int>
    > </xyzzy>
    > <xyzzy>
    > <int>4</int>
    > </xyzzy>
    > <xyzzy>
    > <int>5</int>
    > </xyzzy>
    > </bar>
    > <nodeset>
    > <node>
    > <str>wrong (1)</str>
    > <int>3</int>
    > </node>
    > <node>
    > <str>wrong (2)</str>
    > <int>2</int>
    > </node>
    > <node>
    > <str>right (3)</str>
    > <int>1</int>
    > </node>
    > </nodeset>
    > </foo>


    It *is* working. I'm not sure what the hell you were trying
    to do with the input file like this, though.

    Pray tell me, what did you expect as a result? It is
    supposed to look up the nth <node> in the document for each
    <xyzzy>, where n is the value of an <int> child of <xyzzy>
    in question. Since there are only *three* <node>s in the
    document, naturally, <xyzzy>'s with <int> of 4 and 5 don't
    return bloody anything.

    > I'm wondering if it's not possible to do what I'm trying
    > to do.


    It's been explained no less than three times in this thread
    that what you're trying to do is possible, that your
    problem lies in messed-up contexts, that to get the context
    of the current node you need to use the current() XPath
    function. If you're still unable to grasp that, I recommend
    hiring yourself an XSLT expert. Seriously, that'll save you
    an awful lot of trouble, time and money.

    --
    roy axenov
    roy axenov, Oct 8, 2006
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KathyB
    Replies:
    0
    Views:
    561
    KathyB
    Jul 25, 2003
  2. Kathy Burke
    Replies:
    5
    Views:
    359
    Kathy Burke
    Aug 26, 2003
  3. Xeon

    Intersecting Nodeset

    Xeon, Jul 21, 2003, in forum: XML
    Replies:
    1
    Views:
    398
    Dimitre Novatchev
    Jul 21, 2003
  4. Bryan Galvin
    Replies:
    2
    Views:
    417
    Bryan Galvin
    Sep 29, 2004
  5. Replies:
    1
    Views:
    285
    Mike Meyer
    Oct 28, 2005
Loading...

Share This Page