[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSL Variable not getting set

Subject: Re: XSL Variable not getting set
From: mIchael wolff <wolffmart@xxxxxxxxx>
Date: Wed, 14 Mar 2007 07:38:13 -0700 (PDT)
Re:  XSL Variable not getting set
WHat I am trying to do is....  I get an XML result set
that contains dollar values that are asssociated with
a month.  I need to put these in a CSV and I need to
have a value for every month.  So, if I do not have an
XML node for a certain month, I need to put in a 0.

Here is the code:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:niku="http://www.niku.com/xog/Query">
	<xsl:output method="text"/>
	<xsl:template match="/">
		<xsl:apply-imports />
	</xsl:template>
	<xsl:template
match="niku:QueryResult/niku:Code"><xsl:text></xsl:text></xsl:template>
	
	<xsl:template name="monthly" >
		<xsl:param name="mon" />		
		<xsl:variable name="Found">
			<xsl:for-each select="current-group()">
				<xsl:sort data-type="number" order="ascending"/>
				<xsl:choose>
					<xsl:when test="@month=$mon">,<xsl:value-of
select="@cost"/>
						<xsl:text>test</xsl:text>
					</xsl:when>		
				</xsl:choose>							
			</xsl:for-each>
		</xsl:variable>
		<xsl:if test="$Found = ''">
			<xsl:text>,0</xsl:text>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="niku:QueryResult/niku:Records">
		<xsl:for-each-group select="niku:Record"
group-by="@gl">
			<xsl:for-each-group select="current-group()"
group-by="@fiscalyear">
				<xsl:if test="@fiscalyear != 'null'">
					<xsl:value-of select="@fiscalyear"/>
				</xsl:if>			
				<xsl:text>,</xsl:text>
				<xsl:if test="string(@gl) != 'null'">
					<xsl:value-of select="@gl"/>
				</xsl:if>
				<xsl:text>,</xsl:text>
				
				
				<xsl:call-template name="monthly">
					<xsl:with-param name="mon">1</xsl:with-param>
				</xsl:call-template>
				<xsl:call-template name="monthly">
					<xsl:with-param name="mon">2</xsl:with-param>
				</xsl:call-template>
				<xsl:call-template name="monthly">
					<xsl:with-param name="mon">3</xsl:with-param>
				</xsl:call-template>
				<xsl:call-template name="monthly">
					<xsl:with-param name="mon">4</xsl:with-param>
				</xsl:call-template>
				<xsl:call-template name="monthly">
					<xsl:with-param name="mon">5</xsl:with-param>
				</xsl:call-template>
				<xsl:call-template name="monthly">
					<xsl:with-param name="mon">6</xsl:with-param>
				</xsl:call-template>
				<xsl:call-template name="monthly">
					<xsl:with-param name="mon">7</xsl:with-param>
				</xsl:call-template>
				<xsl:call-template name="monthly">
					<xsl:with-param name="mon">8</xsl:with-param>
				</xsl:call-template>
				<xsl:call-template name="monthly">
					<xsl:with-param name="mon">9</xsl:with-param>
				</xsl:call-template>
				<xsl:call-template name="monthly">
					<xsl:with-param name="mon">10</xsl:with-param>
				</xsl:call-template>
				<xsl:call-template name="monthly">
					<xsl:with-param name="mon">11</xsl:with-param>
				</xsl:call-template>
				<xsl:call-template name="monthly">
					<xsl:with-param name="mon">12</xsl:with-param>
				</xsl:call-template>

			</xsl:for-each-group>
		</xsl:for-each-group>
	</xsl:template>
</xsl:stylesheet>



AND the XML



<QueryResult xmlns="http://www.niku.com/xog/Query">
    <Records>
        <Record cost="2970.0" fiscalyear="2007"
gl="0017016990001001703914F537" month="1"/>
            fiscalyear="2007"
gl="0017016990001001703912H796"
            location="001" month="1" projectclass="12"
            projectkey="5000892" rev_notes="null"
version="405"/>
        <Record cost="3505.0" fiscalyear="2007"
gl="0017016990001001703914F537" month="2"/>
		<Record cost="123.0" fiscalyear="2007"
gl="0017016990001001703914F537"  month="6"/>
    </Records>
</QueryResult>



The desired output would be:

2007,0017016990001001703914F537,2970.0,3505.0,0,0,0,123.0,0,0,0,0,0,0




 
____________________________________________________________________________________
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
http://answers.yahoo.com/dir/?link=list&sid=396546091

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.