www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: please help with this loop

  1. #1
    Join Date
    Jan 2003
    Posts
    45

    Red face please help with this loop

    Hi there,

    I have a problem. In my xsl, I have this variable:
    <xsl:variable name="recordCountDifference" select="50 - count(/Schema1/Claim) mod 50" />

    and then I need to do this loop, and output some tags:

    <xsl:for-each select="$recordCountDifference">
    <br/>
    </xsl:for-each>

    Please help me out.

    Thanks a lot,

    Mike

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    2,653
    you did not mention whats wrong and what error you are getting,where the code is breaking etc

  3. #3
    Join Date
    Jan 2003
    Posts
    45
    well, because i don't know.

    when i view the xsl in IE it works fine, but when I parse it with xml, it gives me error.

    The expression passed to this method should result in a NodeSet.

    this is my complete stylesheet:

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:user="urn:my-scripts"
    xmlns:url="uri:find-url.org"
    >
    <xslutput method="html"/>
    <xslaram name="Employee"></xslaram>
    <xsl:variable name="recordCountDifference" select="50 - count(/Schema1/C) mod 50" />

    <xsl:template match="/">
    <body>
    <link rel="stylesheet" href="Styles/Print.css" type="text/css"/>
    <script for='window' event='onload()'>
    javascript:self.focus();
    javascript:window.print();
    </script>

    <xsl:for-each select="/Schema1/C[position() mod 50 = 1]">
    <xsl:choose>
    <xsl:when test="position() > 1">
    <br/><br/>
    <table width="94%" align="center" cellspacing="0" cellpadding="0">
    <tr>
    <td align="right" class="ClientSideDefault">Page: <xsl:number value="position()"/>
    </td>
    </tr>
    </table>
    <br style="page-break-before:always;"/>
    </xsl:when>
    </xsl:choose>
    <xsl:choose>
    <xsl:when test="position() >= 0">

    <table width="750" align="center" cellspacing="0" cellpadding="0">
    <tr>
    <td width="26%">
    <span class="ClientSide_R_Header">Enter Name: </span>
    </td>
    <td width="20%" align="left">
    <u><span class="ClientSideDefault"><xsl:value-of select="$Employee"/></span></u>
    </td>
    <td align="right">
    </td>
    </tr>
    </table>
    <br/><br/>
    </xsl:when>
    </xsl:choose>
    <table cellspacing="0" Align="center" border="0" id="_ctl1_MyList" style="border-width:0px;width:94%;border-collapse:collapse;">
    <xsl:choose>
    <xsl:when test="position() >= 0">
    <tr>
    <td class="DataHeader">Cant</td>
    </tr>
    </xsl:when>
    </xsl:choose>
    <xsl:apply-templates select=". | following-sibling::C[position() &lt; 50]"/>
    </table>

    </xsl:for-each>
    <xsl:for-each select="$recordCountDifference">

    </xsl:for-each>

    <br/><br/>
    <table width="94%" align="center" cellspacing="0" cellpadding="0">
    <tr>

    <td align="right" class="ClientSideDefault">Page: <xsl:number value="position()"/>
    </td>
    </tr>
    </table>
    </body>
    </xsl:template>
    <xsl:template match="Schema1/C">
    <tr>
    <td class="DataContent"><xsl:value-of select="@Employee"/></td>
    </tr>
    </xsl:template>

    </xsl:stylesheet>


    thanks for your help.

    Mike

  4. #4
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    2,653
    well post some of your xml ..might as well..lol
    I'll take a look

  5. #5
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    2,653
    first things first,I think you have some spelling mistakes in your code

    <xslutput method="html"/>
    <xslaram name="Employee"></xslaram>
    should be

    <xslutput method="html"/>
    <xslaram name="Employee"></xslaram>

  6. #6
    Join Date
    Jan 2003
    Posts
    45
    I don't need to show you the xml, everything in my stylesheet works, if I take this out:
    <xsl:for-each select="$recordCountDifference">

    </xsl:for-each>

    Syntax in xsl shows correct, xml is correct, I don't know. I didn't find any examples of this kind of loop, maybe it's not possible to do it like this.

    Mike

  7. #7
    Join Date
    Jan 2003
    Posts
    45
    BTW. I was in Calgary 3 days ago, when the big storm came. Quite impressive, hey? Have you found anything that could cause my problems?

  8. #8
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    2,653
    suite your self my friend...
    As I spotted 2 mistakes in first glance in your xsl code....who knows what else is wrong..

    good luck..believe me you'd need that

  9. #9
    Join Date
    Jan 2003
    Posts
    45
    Oh no, I didn't want to sound like that. English is my second language, and I am tired too. Try to understand, please.


    I will attatch the xsl file and xml file shortly.

    Thanks and I hope you're not mad.

    Mike

  10. #10
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    2,653
    Mad ..never

    always...

    if you rather,email me..see for me to run your files and see whats going I need files..some time errors are obvious but sometimes in XSL case they are not as obvious because xsl works in recursion...so have to see how it runs and what it produces,.. at least for me thats the case

  11. #11
    Join Date
    Jan 2003
    Posts
    45
    Uff, good. Sometimes people who don't speak english perfectly, they can be interpreted wrong, you know.

    Anyway, I am attatching the two files, I just took some data out of it, I don't think it should metter. And I duplicated records in xml, so you can test the breakdown in xsl.

    I hope you have time to look at it.

    Thank in advance!!!

    Mike

    No, I have to send it to your email...

  12. #12
    Join Date
    Jan 2003
    Posts
    45
    Ok,. I post it here, just notice the smiles, the replace ':P'

    xsl:
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:user="urn:my-scripts"
    xmlns:url="uri:find-url.org"
    >
    <xslutput method="html"/>
    <xslaram name="Employee"/>
    <xsl:variable name="recordCountDifference" select="50 - count(/Schema1/C) mod 50" />

    <xsl:template match="/">
    <body>
    <link rel="stylesheet" href="Styles/Print.css" type="text/css"/>
    <script for='window' event='onload()'>
    java script:self.focus();
    java script:window.print();
    </script>

    <xsl:for-each select="/Schema1/C[position() mod 50 = 1]">
    <xsl:choose>
    <xsl:when test="position() > 1">
    <br/><br/>
    <table width="94%" align="center" cellspacing="0" cellpadding="0">
    <tr>
    <td align="right" class="ClientSideDefault">Page: <xsl:number value="position()"/>
    </td>
    </tr>
    </table>
    <br style="page-break-before:always;"/>
    </xsl:when>
    </xsl:choose>
    <xsl:choose>
    <xsl:when test="position() >= 0">

    <table width="750" align="center" cellspacing="0" cellpadding="0">
    <tr>
    <td width="26%">
    <span class="ClientSide_R_Header">Enter Name: </span>
    </td>
    <td width="20%" align="left">
    <u><span class="ClientSideDefault"><xsl:value-of select="$Employee"/></span></u>
    </td>
    <td align="right">
    </td>
    </tr>
    </table>
    <br/><br/>
    </xsl:when>
    </xsl:choose>
    <table cellspacing="0" Align="center" border="0" id="_ctl1_MyList" style="border-width:0px;width:94%;border-collapse:collapse;">
    <xsl:choose>
    <xsl:when test="position() >= 0">
    <tr>
    <td class="DataHeader">Cant</td>
    </tr>
    </xsl:when>
    </xsl:choose>
    <xsl:apply-templates select=". | following-sibling::C[position() &lt; 50]"/>
    </table>

    </xsl:for-each>
    <xsl:for-each select="$recordCountDifference">

    </xsl:for-each>

    <br/><br/>
    <table width="94%" align="center" cellspacing="0" cellpadding="0">
    <tr>

    <td align="right" class="ClientSideDefault">Page: <xsl:number value="position()"/>
    </td>
    </tr>
    </table>
    </body>
    </xsl:template>
    <xsl:template match="Schema1/C">
    <tr>
    <td class="DataContent"><xsl:value-of select="@Employee"/></td>
    </tr>
    </xsl:template>






    xml:
    <?xml version="1.0" encoding="utf-16"?>
    <Schema1>

    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>
    <C Number="95-0227" Employee="Bush"></C>
    <C Number="96-3349" Employee="paul"></C>
    <C Number="96-0068" Employee="Asdf"></C>



    </Schema1>

  13. #13
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    2,653
    Here is the error
    this line in your code is returning a none node value

    <xsl:variable name="recordCountDifference" select="50 - count(/Schema1/C) mod 50" />

    and at this location

    <xsl:for-each select="$recordCountDifference">

    </xsl:for-each>

    you are trying to run it as a node,which its not.You have to carefully re-think your logic and determine what is it you wanted to do at this point.and with the value,by the way the variable
    $recordCountDifference returns value = 10
    ..I hope it helped..

  14. #14
    Join Date
    Jan 2003
    Posts
    45
    Hello Khalidali63,

    I don't really know how to correct that. Here is what i am trying to do.

    It's a report, and I have certain amount of records displayed on each page. So I am finding out the difference on the last page, so it's 10 from our example, and so I want to but 10 lines on the last page, so the footer apears on the same positioni at the bottom of the last page. You know what I mean?

    So the variable returns 10, and I need to do equivalent of

    for(int i=0;i<=10;i++){
    response.write("<br/>");
    }

    What should I do so it works?

    I want to thank you for your help.

    Mike

  15. #15
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    2,653
    Something like this may be?

    <xsl:choose>
    <xsl:when test="$recordCountDifference=10">
    <xsl:value-of select="$recordCountDifference"/>
    <xsl:text>&lt;br/&gt;</xsl:text>
    </xsl:when>
    <xsltherwise/>
    </xsl:choose>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles