Howdy, Stranger!

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

Categories

XSLT or XPATH counting children matching condition

Josh CodeJosh Code Member Posts: 675
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 Member Posts: 2,900
    : 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 Member Posts: 675
    : : 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 Member Posts: 2,900
    : 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 Member Posts: 4
    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.