XSLT or XPATH counting children matching condition - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

XSLT or XPATH counting children matching condition

Josh CodeJosh Code Posts: 675Member
Thanks in advance for anyone who can assist.

I have an interesting problem in XSLT where I want to end up with a condition symmantically similar to:
= 1">
do something


Using a template matching "p",here is an example input XML file to be transformed:
[code]

This text should appear in transformed version.
web

This text should not be seen.
somethingelse

[/code]

The more specific problem is how to count the number of child nodes that have matching text to "web".

I've tried using a for-each loop with an xsl:variable element to count but xsl:variable can't be updated.

Comments

  • infidelinfidel Posts: 2,900Member
    : Thanks in advance for anyone who can assist.
    :
    : I have an interesting problem in XSLT where I want to end up with a condition symmantically similar to:
    : = 1">
    : do something
    :
    :
    : Using a template matching "p",here is an example input XML file to be transformed:
    : [code]
    :

    This text should appear in transformed version.
    : web
    :

    :

    This text should not be seen.
    : somethingelse
    :

    : [/code]
    :
    : The more specific problem is how to count the number of child nodes that have matching text to "web".
    :
    : I've tried using a for-each loop with an xsl:variable element to count but xsl:variable can't be updated.

    There's a built-in count() function in XPath:

    0">

    I haven't tried it, but I think it'll work.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • Josh CodeJosh Code Posts: 675Member
    : : Thanks in advance for anyone who can assist.
    : :
    : : I have an interesting problem in XSLT where I want to end up with a condition symmantically similar to:
    : : = 1">
    : : do something
    : :
    : :
    : : Using a template matching "p",here is an example input XML file to be transformed:
    : : [code]
    : :

    This text should appear in transformed version.
    : : web
    : :

    : :

    This text should not be seen.
    : : somethingelse
    : :

    : : [/code]
    : :
    : : The more specific problem is how to count the number of child nodes that have matching text to "web".
    : :
    : : I've tried using a for-each loop with an xsl:variable element to count but xsl:variable can't be updated.
    :
    : There's a built-in count() function in XPath:
    :
    : 0">
    :
    : I haven't tried it, but I think it'll work.
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]
    :
    :

    Thanks

    The exact code you gave didn't work but after just replacing the /* with keyword, the nested element, IT WORKED!!

    0">

    Thanks again
  • infidelinfidel Posts: 2,900Member
    : The exact code you gave didn't work but after just replacing the /* with keyword, the nested element, IT WORKED!!
    :
    : 0">

    Yeah, it probably should have been ./* instead of just /*

    Glad I could help.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • jeet1212jeet1212 Posts: 4Member
    if you want to check it for all the children of

    not specific child element ....you can try it...




    do something


    do otherwise




    Thanks!

Sign In or Register to comment.