Web Design and Development Forums

XSL/XML variables & bit of javascript

This is a discussion on "XSL/XML variables & bit of javascript" within the XML, RSS & Atom section. This forum, and the thread "XSL/XML variables & bit of javascript are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > XML, RSS & Atom

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Jan 24th, 2007, 03:03   #1 (permalink)
New Member
 
Join Date: Jan 2007
Location: sydney
Posts: 2
XSL/XML variables & bit of javascript

Hi All..!

I think this is a tough question... I have the XML Layout code below..
I need to use XSL to assign different values to variables 'Severity', 'Probability' & 'Exposre' depending on user selections.

How do I go about doign this?

This is the XML Layout:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<ScoreCardDef>
  <Columns>
    <Column id="EWRMType" type="text">
      <HeaderValue>
        <value>Status</value>
      </HeaderValue>
    </Column>
    <Column id="Severity" type="list">
      <HeaderValue>
        <value>Severity</value>
      </HeaderValue>
      <ListItem key="Severity-1">a</ListItem>
      <ListItem key="Severity-2">b</ListItem>
      <ListItem key="Severity-3">c</ListItem>
      <ListItem key="Severity-3">d</ListItem>
      <ListItem key="Severity-3">e</ListItem>
      <ListItem key="Severity-3">f</ListItem>
      <ListItem key="Severity-3">g</ListItem>
    </Column>
    <Column id="Exposure" type="list">
      <HeaderValue>
        <value>Exposure</value>
      </HeaderValue>
      <ListItem key="Exposure-1">At Least Once A Week</ListItem>
      <ListItem key="Exposure-2">Once A Month Or So</ListItem>
      <ListItem key="Exposure-3">Once Or Twice A Year</ListItem>
      <ListItem key="Exposure-4">Once Or Twice Every 10 Years</ListItem>
      <ListItem key="Exposure-5">Once Or Twice in 100 Years</ListItem>
    </Column>
    <Column id="Probability" type="list">
      <HeaderValue>
        <value>Probability</value>
      </HeaderValue>
      <ListItem key="Probability-1">Happens Often</ListItem>
      <ListItem key="Probability-2">Could Easily Happen</ListItem>
      <ListItem key="Probability-3">Could Happen and Has Happened Here or Elsewhere</ListItem>
      <ListItem key="Probability-4">Hasn't Happened Yet But Could</ListItem>
      <ListItem key="Probability-5">Conceivable, But Only In Extreme Circumstances</ListItem>
    </Column>
    <!-- calc w/ xsl -->
    <Column id="EWRM" type="calc">
      <HeaderValue>
        <value>EWRM</value>
      </HeaderValue>
    </Column>
  </Columns>
  <Total>
  </Total>
</ScoreCardDef>
A snippet of what I've started - not sure if <xsl: text> is right?:
Code: Select all
<xsl:when test="@type='calc'">
                        <xsl:variable name="Severity">
                            <xsl:choose>
                                <xsl:when test="../cell/@key='Severity-1'">
                                    <xsl:text>1000</xsl:text>
                                </xsl:when>
                                <xsl:when test="../cell/@key='Severity-2'">
                                    <xsl:text>300</xsl:text>
                                </xsl:when>
                                <xsl:when test="../cell/@key='Severity-3'">
                                    <xsl:text>100</xsl:text>
                                </xsl:when>
Any help would be greatly appreciated!

Kt
codkat is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 24th, 2007, 21:19   #2 (permalink)
Most Reputable Member
 
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,319
Send a message via Skype™ to ukgeoff
Re: XSL/XML variables & bit of javascript

I think you can forget about using xsl. It sounds like a ready made task for Ajax.

Hows your Ajax knowledge?

Do you want a range of values to be fetched from the server depending on a users response or is it simpler than that?
__________________
Regards
Geoff
ukgeoff is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 24th, 2007, 22:03   #3 (permalink)
Reputable Member
 
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 370
Send a message via MSN to snow
Re: XSL/XML variables & bit of javascript

What your doing looks great - could you post up the full code for debugging?
snow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 25th, 2007, 02:54   #4 (permalink)
New Member
 
Join Date: Jan 2007
Location: sydney
Posts: 2
Re: XSL/XML variables & bit of javascript

Thanks for your replies!
Unfortunately the application will only accept XML/XSL..

However I've done some progress..

I've spoken with someone and they insist my code below is correct with no errors.. can anyone pick up any errors? Because I still get an error within my application.. A very general error: "Unable to calculate: Exception Thrown"

See below code:
Code: Select all
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:foo="http://www.pacificedge.com/foo" extension-element-prefixes="msxsl" exclude-result-prefixes="foo">
  <xsl:output method="html" />
  <xsl:variable name="calcNameId">
    <xsl:value-of select="generate-id()" />
  </xsl:variable>
  <msxsl:script language="javascript" implements-prefix="foo">
    <![CDATA[
            var total = 0;
            function MultiplyCalc(Severity,Exposure,Probability)
            {
                var total = Severity * Exposure * Probability;
                return total;
            }
            
        ]]>
  </msxsl:script>
  <xsl:template match="root">
    <TABLE border="1" width="100%">
      <xsl:apply-templates select="columns" />
      <xsl:apply-templates select="row" />
    </TABLE>
  </xsl:template>
  <xsl:template match="columns">
    <TR>
      <xsl:for-each select="*/HeaderValue">
        <TD class="Heading">
          <xsl:value-of select="value" />
        </TD>
      </xsl:for-each>
    </TR>
  </xsl:template>
  <xsl:template match="row">
    <TR>
      <xsl:for-each select="*">
        <xsl:choose>
          <xsl:when test="@type='text'">
            <TD class="RHC" style="width:300px;">
              <DIV>
                <xsl:attribute name="id">
                  <xsl:value-of select="@id" />
                </xsl:attribute>
                <xsl:value-of select="value" />
              </DIV>
            </TD>
          </xsl:when>
          <xsl:when test="@type='list'">
            <TD class="RHC">
              <TABLE WIDTH="100%">
                <TR>
                  <TD align="center">
                    <xsl:choose>
                      <xsl:when test="//root/@readonly='true'">
                        <xsl:for-each select="ListItem">
                          <xsl:if test="@selected='true'">
                            <xsl:value-of select="text()" />
                          </xsl:if>
                        </xsl:for-each>
                      </xsl:when>
                      <xsl:otherwise>
                        <SELECT onchange="fnSelect_Onchange();">
                          <xsl:attribute name="id">
                            <xsl:value-of select="@id" />
                          </xsl:attribute>
                          <xsl:attribute name="nodeName">
                            <xsl:value-of select="@nodeName" />
                          </xsl:attribute>
                          <xsl:attribute name="rowId">
                            <xsl:value-of select="@rowId" />
                          </xsl:attribute>
                          <xsl:if test="//root/@readonly='true'">
                            <xsl:attribute name="DISABLED">true</xsl:attribute>
                          </xsl:if>
                          <xsl:for-each select="ListItem">
                            <OPTION>
                              <xsl:if test="@selected='true'">
                                <xsl:attribute name="SELECTED">
                                  <xsl:value-of select="@selected" />
                                </xsl:attribute>
                              </xsl:if>
                              <xsl:attribute name="value">
                                <xsl:value-of select="@key" />
                              </xsl:attribute>
                              <xsl:value-of select="text()" />
                            </OPTION>
                          </xsl:for-each>
                        </SELECT>
                      </xsl:otherwise>
                    </xsl:choose>
                  </TD>
                </TR>
              </TABLE>
            </TD>
          </xsl:when>
          <xsl:when test="@type='calc'">
            <xsl:variable name="Severity">
              <xsl:choose>
                    <xsl:when test="../cell/@key='Severity-1'">1000</xsl:when>
                    <xsl:when test="../cell/@key='Severity-2'">300</xsl:when>
                    <xsl:when test="../cell/@key='Severity-3'">100</xsl:when>
                    <xsl:when test="../cell/@key='Severity-4'">30</xsl:when>
                    <xsl:when test="../cell/@key='Severity-5'">10</xsl:when>
                    <xsl:when test="../cell/@key='Severity-6'">3</xsl:when>
                    <xsl:when test="../cell/@key='Severity-7'">1</xsl:when>
              </xsl:choose>
            </xsl:variable>
            <xsl:variable name="Exposure">
              <xsl:choose>
                <xsl:when test="../cell/@key='Exposure-1'">10</xsl:when>
                <xsl:when test="../cell/@key='Exposure-2'">3</xsl:when>
                <xsl:when test="../cell/@key='Exposure-3'">1</xsl:when>
                <xsl:when test="../cell/@key='Exposure-4'">0.3</xsl:when>
                <xsl:when test="../cell/@key='Exposure-5'">0.1</xsl:when>
              </xsl:choose>
            </xsl:variable>
            <xsl:variable name="Probability">
              <xsl:choose>
                <xsl:when test="../cell/@key='Probability-1'">1</xsl:when>
                <xsl:when test="../cell/@key='Probability-2'">0.3</xsl:when>
                <xsl:when test="../cell/@key='Probability-3'">0.1</xsl:when>
                <xsl:when test="../cell/@key='Probability-4'">0.03</xsl:when>
                <xsl:when test="../cell/@key='Probability-5'">0.01</xsl:when>
              </xsl:choose>
            </xsl:variable>
           <xsl:if test="@name='EWRM'">
              <TD class="RHC" align="center" type="calc" dataKey="EWRM" style="width:50px;">
                <xsl:value-of select="foo:MultiplyCalc($Severity,$Exposure,$Probability)" />
              </TD>
            </xsl:if>
          </xsl:when>        
        </xsl:choose>
      </xsl:for-each>
    </TR>
  </xsl:template>
</xsl:stylesheet>
Thanks for your help! =)

Kat
codkat is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 25th, 2007, 09:56   #5 (permalink)
Reputable Member
 
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 370
Send a message via MSN to snow
Re: XSL/XML variables & bit of javascript

Hi there,

from a quick look at your code I can't find anything wrong... however, that error should only be raised by the JavaScript you've got in there. Have you checked the values that you're putting into the method?

Tell us if they're valid or if you manage to get us sorted and tell us how!

All the best,
Snow
snow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
variable, xml, xsl

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript Variables russellbain Java, JSP, Cold Fusion 1 Aug 9th, 2007 18:53
PhP variables added to XML mavedog21 PHP Forum 0 Nov 28th, 2006 16:09
Variables!! bionics PHP Forum 6 Apr 25th, 2006 15:39
Get URL and use variables JamieH PHP Forum 2 Jan 1st, 2006 03:13
Session Variables ekendricks ASP Forum 4 Dec 19th, 2003 06:33



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 23:05.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59