Help with select statment on for-each

Discussion in 'XML' started by Bill Sneddon, Jun 27, 2003.

  1. Bill Sneddon

    Bill Sneddon Guest

    I am using the for-each below to build a table where the header is
    a unique nonblank EQUIP_TYPE. This works well.

    What I would like to do is not execute the for loop on on EQUIP_TYPE
    unless one of the AUTOMATED tags equals YES.

    I can change the data so that each row whould contain a tag that
    shows if the EQUIP_TYPE has an AUTOMATED member but that seems wasteful.



    <xsl:key name="tools-by-type" match="row" use="EQUIP_TYPE"/>
    <xsl:template match="document">
    <xsl:for-each select="row[count(. | key('tools-by-type', EQUIP_TYPE)[1])
    = 1 and EQUIP_TYPE[string-length()>0 ] ">


    sample of the XML

    <document>
    <row rowNumber="1">
    <EQUIP_TYPE>ASH</EQUIP_TYPE>
    <TOOL_NAME>ASHZ01ED</TOOL_NAME>
    <AUTOMATED>YES</AUTOMATED>
    </row>
    <row rowNumber="2">
    <EQUIP_TYPE>ASH</EQUIP_TYPE>
    <TOOL_NAME>ASHZ02ED</TOOL_NAME>
    <AUTOMATED>YES</AUTOMATED>
    </row>
    </document>
     
    Bill Sneddon, Jun 27, 2003
    #1
    1. Advertising

  2. Bill Sneddon

    Marrow Guest

    Hi Bill,

    I'm not absolutely sure what you want... but I think you are saying...

    1) select the rows based on distinct <EQUIP_TYPE>
    2) but only where the <EQUIP_TYPE> is not 'empty'
    3) and where any one of the rows within that distinct <EQUIP_TYPE> value has
    an <AUTOMATED> of 'YES'

    If so, then perhaps you need something like...

    <xsl:for-each select="row[EQUIP_TYPE/text()]
    [generate-id() =
    generate-id(key('tools-by-type',EQUIP_TYPE))]

    [key('tools-by-type',EQUIP_TYPE)/AUTOMATED = 'YES']">

    (nb. the predicates are respective to the numbered filter conditions above).

    BTW, you are better to use the generate-id() version of the Muenchian
    Technique as it generally performs better than the count() version of the
    same technique.

    Hope this helps
    Marrow
    http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    http://www.topxml.com/Xselerator



    "Bill Sneddon" <> wrote in message
    news:bdhqln$3iq$...
    > I am using the for-each below to build a table where the header is
    > a unique nonblank EQUIP_TYPE. This works well.
    >
    > What I would like to do is not execute the for loop on on EQUIP_TYPE
    > unless one of the AUTOMATED tags equals YES.
    >
    > I can change the data so that each row whould contain a tag that
    > shows if the EQUIP_TYPE has an AUTOMATED member but that seems wasteful.
    >
    >
    >
    > <xsl:key name="tools-by-type" match="row" use="EQUIP_TYPE"/>
    > <xsl:template match="document">
    > <xsl:for-each select="row[count(. | key('tools-by-type', EQUIP_TYPE)[1])
    > = 1 and EQUIP_TYPE[string-length()>0 ] ">
    >
    >
    > sample of the XML
    >
    > <document>
    > <row rowNumber="1">
    > <EQUIP_TYPE>ASH</EQUIP_TYPE>
    > <TOOL_NAME>ASHZ01ED</TOOL_NAME>
    > <AUTOMATED>YES</AUTOMATED>
    > </row>
    > <row rowNumber="2">
    > <EQUIP_TYPE>ASH</EQUIP_TYPE>
    > <TOOL_NAME>ASHZ02ED</TOOL_NAME>
    > <AUTOMATED>YES</AUTOMATED>
    > </row>
    > </document>
    >
     
    Marrow, Jun 27, 2003
    #2
    1. Advertising

  3. Bill Sneddon

    Bill Sneddon Guest

    Yes you understood what I wanted thank you for being so helpful.
    It will be a little while before I can test this but will test again
    when that time comes.


    Marrow wrote:
    > Hi Bill,
    >
    > I'm not absolutely sure what you want... but I think you are saying...
    >
    > 1) select the rows based on distinct <EQUIP_TYPE>
    > 2) but only where the <EQUIP_TYPE> is not 'empty'
    > 3) and where any one of the rows within that distinct <EQUIP_TYPE> value has
    > an <AUTOMATED> of 'YES'
    >
    > If so, then perhaps you need something like...
    >
    > <xsl:for-each select="row[EQUIP_TYPE/text()]
    > [generate-id() =
    > generate-id(key('tools-by-type',EQUIP_TYPE))]
    >
    > [key('tools-by-type',EQUIP_TYPE)/AUTOMATED = 'YES']">
    >
    > (nb. the predicates are respective to the numbered filter conditions above).
    >
    > BTW, you are better to use the generate-id() version of the Muenchian
    > Technique as it generally performs better than the count() version of the
    > same technique.
    >
    > Hope this helps
    > Marrow
    > http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    > http://www.topxml.com/Xselerator
    >
    >
    >
    > "Bill Sneddon" <> wrote in message
    > news:bdhqln$3iq$...
    >
    >>I am using the for-each below to build a table where the header is
    >>a unique nonblank EQUIP_TYPE. This works well.
    >>
    >>What I would like to do is not execute the for loop on on EQUIP_TYPE
    >>unless one of the AUTOMATED tags equals YES.
    >>
    >>I can change the data so that each row whould contain a tag that
    >>shows if the EQUIP_TYPE has an AUTOMATED member but that seems wasteful.
    >>
    >>
    >>
    >><xsl:key name="tools-by-type" match="row" use="EQUIP_TYPE"/>
    >><xsl:template match="document">
    >><xsl:for-each select="row[count(. | key('tools-by-type', EQUIP_TYPE)[1])
    >>= 1 and EQUIP_TYPE[string-length()>0 ] ">
    >>
    >>
    >>sample of the XML
    >>
    >><document>
    >> <row rowNumber="1">
    >><EQUIP_TYPE>ASH</EQUIP_TYPE>
    >><TOOL_NAME>ASHZ01ED</TOOL_NAME>
    >><AUTOMATED>YES</AUTOMATED>
    >> </row>
    >> <row rowNumber="2">
    >><EQUIP_TYPE>ASH</EQUIP_TYPE>
    >><TOOL_NAME>ASHZ02ED</TOOL_NAME>
    >><AUTOMATED>YES</AUTOMATED>
    >> </row>
    >></document>
    >>

    >
    >
     
    Bill Sneddon, Jun 28, 2003
    #3
    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. JL

    Return statment

    JL, Dec 17, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    405
    Hermit Dave
    Dec 17, 2003
  2. crjunk
    Replies:
    2
    Views:
    1,608
    crjunk
    Sep 3, 2004
  3. Luk
    Replies:
    2
    Views:
    325
    Andrew Thompson
    Feb 10, 2004
  4. jesusR
    Replies:
    1
    Views:
    336
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Oct 11, 2006
  5. Jim in Arizona

    if statment based on elapsed time ..

    Jim in Arizona, Dec 14, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    369
    Rad [Visual C# MVP]
    Dec 15, 2006
Loading...

Share This Page