Solved

XSL problem

Posted on 2004-04-23
9
209 Views
Last Modified: 2008-02-20
I have a display problem.  I am trying to use a combination of JavaScript and XSL to create a display.
Currently our application has a stored procedure that returns a list of clients and a list of client services each has received in the past year.  The rows representing each service are grouped by individual, and vary in number from 1-10. (One individual may have only one row , whereas others may have any number up to 10). A unique system identifier (numerical) is used for the grouping.  For ease of identifying the rows for a given individual, I would like to alternate or change the background color to indicate the individuals listed.
0
Comment
Question by:missqti
  • 4
  • 3
9 Comments
 
LVL 26

Expert Comment

by:rdcpro
ID: 10902610
I assume you're not having trouble with the grouping?  Do you want the sub-rows under each individual alternating background color, or do you want the individuals (plus their rows) the same color, but alternate between individuals?

Also, post what you have so far (xml and xsl), as it's easier to edit your code than it is to write a complete example. But the general approach is to use the modulo function to decide whether a row is even or odd.  There's an additional complication because you're grouping, but you still use the same basic approach.  As long as the xsl:apply-templates or xsl:for-each does the grouping of the nodes, you can still do something like:

<xsl:variable name="vBackground">
    <xsl:choose>
        <xsl:when test="position() mod 2 = 0">even_row</when>
        <xsl:otherwise>odd_row</xsl:otherwise>
    </xsl:choose>
</xsl:variable>

<tr class="{$vBackground}">

Regards,
Mike Sharp
0
 

Author Comment

by:missqti
ID: 10902750
rdcpo first of all i would like to thanks for your quick response. Yes I don't have any problem of grouping. To answere your question. This is what I need (the individuals (plus their rows) the same color, but alternate between individuals).

This is what I got so far for my xsl and it displayed just one color only.

<xsl:template match="Client">
<tr class="Grid">
<xsl:attribute name="style">background-color:
    <xsl:eval>fnNewPFRP()</xsl:eval>
</xsl:attribute>

<xsl:choose>
<xsl:when test="SysID[.$eq$ //SelectedClient/SysID]">
     <xsl:choose>
     <xsl:when test="PrsnID [.$eq$ //SelectedClient/PrsnID]">
     <xsl:attribute name="style">background-color:
     <xsl:eval>fnIsOdd()</xsl:eval>; font-weight: bold; color:     blue;
      </xsl:attribute>
     </xsl:when>
      <xsl:otherwise>
       <xsl:attribute name="style">background-color:
       <xsl:eval>fnIsOdd()</xsl:eval>
      </xsl:attribute>
      </xsl:otherwise>
    </xsl:choose>
     </xsl:when>
<xsl:otherwise>
<xsl:attribute name="style">background-color: <xsl:eval>fnIsOdd()</xsl:eval></xsl:attribute>
</xsl:otherwise>
</xsl:choose>

This is my JavaScript:

<xsl:script>

var CurrentPFRP;
var PreviousPFRP;
var CurrentRowColor = "white";


function fnNewPFRP (CurrentPFRP)
{
    if (CurrentPFRP == PreviousPFRP)
   {
    return CurrentRowColor ;
    }
  else
    {
          if (CurrentRowColor = "white");
          {
      CurrentRowColor = "gray";
         }
       else
         {
          CurrentRowColor = "white";
         }
         PreviousPFRP = CurrentPFRP;
        return CurrentRowColor;
    }
}

0
 
LVL 26

Expert Comment

by:rdcpro
ID: 10902947
Do you really have to use that old parser?  It would be much better to use MSXML 3 for this.  In fact, the old MSXML 2 syntax is so old I forget the exact way to use modulo math, if it was even possible.  You'll probably have a hard time finding documentation for it these days.

Also, it's very bad to use global variables in extension functions.  XSLT is supposed to be a side-effects-free language, and you cannot guarantee what order your templates will be processed in.   MSXML 3 has a much better way of grouping, as well as handling your specific situation.  If you really need to support IE 5/5.5, and your users might not have MSXML 3 on their systems, it's possible to automatically install the parser using an <object> tag in an HTML page.  See:  

http://rdcpro.com/zones/xml/faqroot/msxmlredist/

If this is being done server-side, (which might be the case, now that I see you're using a stored procedure), then definitely DON'T use MSXML 2!  Use MSXML 3 or 4, and the current XSLT syntax.  If you post a snippet of the XML (showing at least a few individuals), I'll put an example together.

Regards,
Mike Sharp
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 10902982
By the way, to see how you can handle grouping of flat XML in MSXML 3, take a look at my Muenchian Grouping tutorial, as well as some of my code snippets:

http://rdcpro.com/zones/xml/xslt/faqroot/faq-grouping-1.1/
Using XPath for grouping:
http://rdcpro.com/Members/rdcpro/snippets/xpathgrouping/
http://rdcpro.com/Members/rdcpro/snippets/xpathgrouping2/
Using Muenchian techniques for grouping:
http://rdcpro.com/Members/rdcpro/snippets/columnrowgrouping/
http://rdcpro.com/Members/rdcpro/snippets/groupinggrades/

Regards,
Mike Sharp
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:missqti
ID: 10904764
Mike

Thanks for the Answer. I will try this out to see if it work. How complicate to move from MSXML2 to MSXML3 or 4.

What is the most common that people are using now 3 or 4?

Why is the problem to user MSXML2 with store procedure?

thanks,
missqti
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 10905258
I would say that MSXML 2 is now in the minority.  It's the default parser for IE 5/5.5, but if the user has MSXML 3 installed, it will work in those browsers.  MSXML 3 is installed by any one of a number of applications, including IE 6, so often your user has it anyway.  MSXML 2 is around 6 or so years old (came out early 1998 IIRC).  It's not very fast, non-standard, has some bugs and security issues, and while I've written tons of code for it, I haven't found the need to use it in years.  I can't imagine spending time writing obsolete code!  MSXML 3 will, however, still run your legacy MSXML 2 code (as long as you use at least MSXML 3 sp1 or later), so you can upgrade your code at your convenience.

Grouping, especially complex grouping, is MUCH easier to do with MSXML 3 or later.

MSXML 4 is less commonly installed, because it doesn't come with IE 6, but it's necessary if you want to use W3C XML Schemas.  It's faster too.  But then MSXML 3 is much faster than MSXML 2...

Any of the parsers can be auto-installed to the client, as I mentioned before.  

Moving to the new parser is a little complicated in that the XSL syntax of MSXML 2 is non-standard.  But there's a lot more you can do with the standard XSLT syntax anyway, so you might find your XSL stylesheets get simpler.  

No problem with MSXML 2 parsing the XML generated by a stored proc...the problem is using MSXML 2 on the server.  It's simply unnecessary, and depending on what you're doing, it's unsafe.  

Is this transformation happening on the server, or the client?  How do you load the XML, and how do you call the transformation?

Regards,
Mike Sharp
0
 

Author Comment

by:missqti
ID: 10920030
Mike !!!

Here is my a snippet of the XML (showing at least a few individuals)

<?xml version="1.0" ?>
<?xml-stylesheet type='text/xsl' href='../xxxxxxx.asp' ?>

<PAGESETUP>

<WebAppFunction classname="CREG.Lookup" funcName="SelClient">

<Params>
      <FirstRecord>1</FirstRecord>
      <LastRecord>25</LastRecord>
      <NumberOfClientsInSearch>43
               </NumberOfClientsInSearch>
      <SearchPage>1</SearchPage>
      <NumberOfRecsPerPage>25
                </NumberOfRecsPerPage>
      <SortSearchByColumn>0
              </SortSearchByColumn>
      <SearchOrder>25</SearchOrder>

            <NextPage>
            <Params>
            <SearchPage>2</SearchPage>
            </Params>
            <FirstRecord>26</FirstRecord>
            <LastRecord>50</LastRecord>
            </NextPage>
            </Params>

<Clients>
<Headings>
      <heading index="1" xmltag="ProgramName">
            Program Name
      </heading>
      <heading index="2" xmltag="ClientName">
            Client Name
      </heading>
      <heading index="3" xmltag="DateOfBirth">
            Birth Date</heading>
      <heading index="4" xmltag="Gender">
            Sex
      </heading>
      <heading index="5" xmltag="SSN">
            SSN
      </heading>
      <heading index="6" xmltag="DateLastKnown">
            Updated
      </heading>
      <heading index="7" xmltag="PrsnID">
            Client ID
      </heading>
      <heading index="8" xmltag="Ethnicity">
            Ethnicity
      </heading>
      <heading index="9" xmltag="Hispanic">
            Hispanic
      </heading>
</Headings>

<WebAppFunction classname="CREG.Lookup" funcName="ClientDisplay">
<Params>
<QueryString>ClientDisplay.aspsysID=15&amp;PrsnID=xxx
</QueryString>
</Params>

<Client>
      <SysID>11</SysID>
      <PrsnID>479746131</PrsnID>
      <ProgramName>BASIC FOOD
              </ProgramName>
      <Client_Name>JACKSON, MICHAEL
               </Client_Name>
      <Birth_Date>04/26/60</Birth_Date>
      <Sex>M</Sex>
      <SSN>111-22-3333 </SSN>
      <Updated>3/2/2004</Updated>
      <ServiceEnd>200402</ServiceEnd>
      <Client_ID>0000000</Client_ID>
      <Ethnicity>White</Ethnicity>
      <Hispanic>Not Hispanic</Hispanic>
</Client>
</WebAppFunction>

<WebAppFunction classname="CREG.Lookup" funcName="ClientDisplay">
<Params>
      <QueryString>ClientDisplay.asp?SysID=88&amp;PrsnID=XXXXXX </QueryString>
</Params>

<Client>
      <SysID>55</SysID>
      <PrsnID>379871 </PrsnID>
      <ProgramName>CHILDRENS </ProgramName>
      <Client_Name>TAYLOR, ANN</Client_Name>
      <Birth_Date>12/25/80</Birth_Date>
      <Sex>F</Sex>
      <SSN>556-77-9999</SSN>
      <Updated>3/10/2004</Updated>
      <ServiceEnd>200402</ServiceEnd>
      <Client_ID>00000</Client_ID>
      <Ethnicity>Not_Reported</Ethnicity>
      <Hispanic>Not Reported</Hispanic>
      </Client></WebAppFunction>
</WebAppFunction>

<WebAppFunction classname="CREG.Lookup" funcName="ClientDisplay">
<Params>
      <QueryString>ClientDisplay.aspSysID=X&amp;                 PrsnID=xxxxxxxxx
      </QueryString>
</Params>

<Client>
      <SysID>99</SysID>
      <PrsnID>48971 </PrsnID>
      <ProgramName>CHILDRENS </ProgramName>
      <Client_Name>TAYLOR, ANN B</Client_Name>
      <Birth_Date>12/25/80</Birth_Date>
      <Sex>F</Sex>
      <SSN>556-77-9999</SSN>
      <Updated>3/10/2004</Updated>
      <ServiceEnd>200402</ServiceEnd>
      <Client_ID>00000</Client_ID>
      <Ethnicity>Not_Reported</Ethnicity>
      <Hispanic>Not Reported</Hispanic>
      </Client></WebAppFunction>
</WebAppFunction>


<WebAppFunction classname="CREG.Lookup" funcName="ClientDisplay">
<Params>
      <QueryString>ClientDisplay.aspSysID=x&amp;PrsnID=xxxxxx
      </QueryString>
</Params>
<Client>
      <SysID>08</SysID>
      <PrsnID>32648 </PrsnID>
      <ProgramName>CHILDRENS </ProgramName>
      <Client_Name>DONNA, KAREN/Client_Name>
      <Birth_Date>12/25/45</Birth_Date>
      <Sex>F</Sex>
      <SSN>111-99-8888</SSN>
      <Updated>3/10/2004</Updated>
      <ServiceEnd>200402</ServiceEnd>
      <Client_ID>00000</Client_ID>
      <Ethnicity>Not_Reported</Ethnicity>
      <Hispanic>Not Reported</Hispanic>
      </Client></WebAppFunction>
</WebAppFunction>

</PAGESETUP>

=====================================
To answer your question:
Is this transformation happening on the server, or the client?  ==>Client
How do you load the XML ==> Read as a data stream
How do you call the transformation? ==> Invoked as part of our very large xls file called xxxxxxx.asp

=====================================

Thanks,
Missqti

0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12632731
PAQed with points refunded (180)

modulo
Community Support Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now