Counting 'empty' nodes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dd

    #1

    Counting 'empty' nodes

    Given the bolow sample, I need to count the elements <quick> with a
    child 'yes'. The result for this sample should, of couse, be '1', but I
    cannot figure out how to write the expression in the
    <xsl:template select="????">
    I tried count(//quick/*) >0
    which returns false...


    <?xml version="1.0" encoding="UTF-8"?>
    <dffob>
    <destinations >
    <dest>
    <quick/>
    </dest>
    <dest>
    <quick>yes</quick>
    </dest>
    </destinations>
    </dffob>
  • Bjoern Hoehrmann

    #2
    Re: Counting 'empty' nodes

    * dd wrote in comp.text.xml:[color=blue]
    >Given the bolow sample, I need to count the elements <quick> with a
    >child 'yes'. The result for this sample should, of couse, be '1', but I
    >cannot figure out how to write the expression in the
    ><xsl:templat e select="????">
    >I tried count(//quick/*) >0[/color]

    * only matches element nodes while "yes" is a text node. You can

    count(//quick/text())

    But that would also count

    <quick> </quick>

    So

    count(//quick[.="yes"])

    might be better.

    Comment

    • dd

      #3
      Re: Counting 'empty' nodes

      Bjoern Hoehrmann wrote:[color=blue]
      > * dd wrote in comp.text.xml:
      >[color=green]
      >>Given the bolow sample, I need to count the elements <quick> with a
      >>child 'yes'. The result for this sample should, of couse, be '1', but I
      >>cannot figure out how to write the expression in the
      >><xsl:templa te select="????">
      >>I tried count(//quick/*) >0[/color]
      >
      >
      > * only matches element nodes while "yes" is a text node. You can
      >
      > count(//quick/text())
      >
      > But that would also count
      >
      > <quick> </quick>
      >
      > So
      >
      > count(//quick[.="yes"])
      >
      > might be better.[/color]
      Tried this also:
      <?xml version="1.0" encoding="UTF-8" ?>
      <xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
      version="1.0">
      <xsl:template match="/">
      <xsl:apply-templates select="count(//quick[. ='yes'])"/>
      </xsl:template>

      </xsl:stylesheet>

      Oxygen returns: value is not a node set

      Comment

      • dd

        #4
        Re: Counting 'empty' nodes

        dd wrote:
        [color=blue]
        > Bjoern Hoehrmann wrote:
        >[color=green]
        >> * dd wrote in comp.text.xml:
        >>[color=darkred]
        >>> Given the bolow sample, I need to count the elements <quick> with a
        >>> child 'yes'. The result for this sample should, of couse, be '1', but
        >>> I cannot figure out how to write the expression in the
        >>> <xsl:template select="????">
        >>> I tried count(//quick/*) >0[/color]
        >>
        >>
        >>
        >> * only matches element nodes while "yes" is a text node. You can
        >>
        >> count(//quick/text())
        >>
        >> But that would also count
        >>
        >> <quick> </quick>
        >>
        >> So
        >>
        >> count(//quick[.="yes"])
        >>
        >> might be better.[/color]
        >
        > Tried this also:
        > <?xml version="1.0" encoding="UTF-8" ?>
        > <xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
        > version="1.0">
        > <xsl:template match="/">
        > <xsl:apply-templates select="count(//quick[. ='yes'])"/>
        > </xsl:template>
        >
        > </xsl:stylesheet>
        >
        > Oxygen returns: value is not a node set[/color]

        Sorry, seems that count(//quick[. = 'yes']) does work.

        Many thanks.

        Comment

        • Martin Honnen

          #5
          Re: Counting 'empty' nodes



          dd wrote:
          [color=blue]
          > Bjoern Hoehrmann wrote:
          >[color=green]
          >> * dd wrote in comp.text.xml:
          >>[color=darkred]
          >>> Given the bolow sample, I need to count the elements <quick> with a
          >>> child 'yes'. The result for this sample should, of couse, be '1', but
          >>> I cannot figure out how to write the expression in the
          >>> <xsl:template select="????">
          >>> I tried count(//quick/*) >0[/color]
          >>
          >>
          >>
          >> * only matches element nodes while "yes" is a text node. You can
          >>
          >> count(//quick/text())
          >>
          >> But that would also count
          >>
          >> <quick> </quick>
          >>
          >> So
          >>
          >> count(//quick[.="yes"])
          >>
          >> might be better.[/color]
          >
          > Tried this also:
          > <?xml version="1.0" encoding="UTF-8" ?>
          > <xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
          > version="1.0">
          > <xsl:template match="/">
          > <xsl:apply-templates select="count(//quick[. ='yes'])"/>[/color]


          Well you need
          <xsl:value-of select="count(//quick[. ='yes'])"/>
          if you want to output the value. xsl:apply-templates tries to apply
          templates against the select attribute value and that has then indeed to
          be a nodeset.

          --

          Martin Honnen
          http://JavaScript.FAQTs.com/

          Comment

          Working...