Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

XSL problem

Posted on 2004-04-23
9
Medium Priority
?
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 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