Welcome!

PowerBuilder Authors: Pat Romanski, Dan Joe Barry, Ian Thain, Yakov Werde, Paul Slater

Related Topics: PowerBuilder

PowerBuilder: Article

Web Services Implementation of a Third Kind

Redeploying existing Web Services using the new ASP.NET Web Services target in PowerBuilder 11

If there were no matching records in the XML file, another test is made on the "startrow" argument that was passed into the stylesheet, which indicates whether this was the first page of results or an attempt to display a later page. If it was the first page of results, a message is simply returned indicating that there were no matching records. If it was a later page of results, the "links" template is called to display links to prior result pages, and then the message is provided to indicate that there are no further results.

Next comes the "rows" template used to display the rows. It starts off simply enough, generating a table to display the result sets. However, then we encounter a xsl:variable called "msgid" that's actually the result of a call to a JavaScript function embedded in the XSLT file. That variable is then used to generate the hyperlink that will be used from the results page to call the display page. The remainder of the template is simple formatting of the remainder of the table, including the specification of the font color to use for the line that contains the group, message data, and author.

After that is the "links" template used to display the links to other pages in the result set. Once again we count the number of "search_row" tags in the XML and assign that to a variable called "count." Then we generate a link to the first page of the report using the arguments passed into the stylesheet and setting the "startrow" to 1 (as if the user was doing a new search).

If the startrow for this result page is greater than 1 we determine the number of pages prior to this page by dividing the number of rows in the total result set (another stylesheet argument) by the current startrow. We then do another xsl:call-template tag to invoke another embedded stylesheet ("createlinks"). This time we also use a set of xsl:with-param tags to pass arguments to that stylesheet, including the total number of prior pages we just calculated. Finally, if the count is greater than 0, we then check to see whether we've hit the last page of the results. If not, we generate a "Next" page link.

Then we come to the "createlinks" template. Once again there are a couple of xsl:param tags to accept the incoming arguments. We then check to see whether the "currentpage" argument (which was originally passed in as 1 when it was called from the main template) is less than or equal to the total number of pages. You'll see why in a minute. Next we calculate what the starting row number would be for that page and assign it to a xsl:variable called "newstart." That variable is then used to generate a link for that page number.

Here comes the tricky part. We then hit an xsl:call-template and a set of xsl:with-param tags. What's being called though is this same "createlinks" template. That is the "createlinks" template calls itself recursively incrementing the "currentpage" argument by 1 on each pass, until it's performed the operation a "totalpages" number of times.

Finally we hit a msxsl:script tag. This is our embedded JavaScript function. The problem we need to address is that the message ID that we're using to refer to begins and ends with, and can sometimes include, characters that can't be used literally in a URL (i.e., in the links we're generating). What we're doing here is calling the JavaScript encodeURI function to encode the messageID so it can be used in a URL. Actually, I strip the first and last characters off of the message ID first (that's why there's a sub-string call on the argument as it's being passed into the encodeURI function) and those are added back on in the display method of my PowerBuilder component. The remaining argument is automatically decoded by ASP.Net when it passed it into the Web Service.

Conclusions
That's it. As you can see, it's very easy to create ASP.NET Web Services using PowerBuilder 11. It's also very easy to use XSLT to transform the results from such services into HTML pages using ASP.NET. Finally, you've also seen how it's possible to generate somewhat more sophisticated results using some more advanced features of XSLT.

More Stories By Bruce Armstrong

Bruce Armstrong is a development lead with Integrated Data Services (www.get-integrated.com). A charter member of TeamSybase, he has been using PowerBuilder since version 1.0.B. He was a contributing author to SYS-CON's PowerBuilder 4.0 Secrets of the Masters and the editor of SAMs' PowerBuilder 9: Advanced Client/Server Development.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.