Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Error in XPath Expression

From: xslspy@-----------.---------.---
To: NULL
Date: 11/2/2005 7:29:00 AM
I think its in table context ... here is my complete xsl..

<xslt:stylesheet version="1.0"
      xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xslt:output media-type="text/html" encoding="UCS-2"/>
<xslt:output method="html"/>
<xslt:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xslt:variable name="SortDirection">0</xslt:variable>	
<xslt:variable name="SortColumn">0</xslt:variable>
<xslt:variable name="SortColor">#FFF0F0</xslt:variable>
<xslt:variable name="Culture">en-US</xslt:variable>
<xslt:variable name="GroupByCol"> </xslt:variable>
<xslt:variable name="color1">white</xslt:variable>
<xslt:variable name="color2">#F8F7F7</xslt:variable>
<xslt:variable name="color3">#F8F8F8</xslt:variable>

<xslt:variable name="SortImage">  </xslt:variable>
<xslt:key name="NewDataSet" match="Table" use="sAssignedUser"/>
<xslt:key name="NewDataSet" match="Table" use="RowId"/>
<xslt:template match="/">
  		<table border="0" cellpadding="0" cellspacing="0" width="100%">
			<tr>
				<td align="center">Contract Number</td>
				<td align="center">Contract Name</td>
				<td align="center">Status</td>
				<td align="center">Assigned User</td>
				<td align="center">start Value</td>
			</tr>
			<xslt:call-template name="Group"/>	
		</table>
</xslt:template>
<xslt:template name="Sort" match="NewDataSet">
	<xslt:for-each select="/NewDataSet/Table">
		<!--<xslt:sort order="ascending" select="concat(substring(@startdate, 
9,2),substring(@startdate, 6,2),substring(@startdate, 1,4))" /> -->
		<xslt:sort select="sAssignedUser" order="ascending"/>
		<tr>
			<td><xslt:value-of select="sContractNumber"/></td>
			<td><xslt:value-of select="sContractName"/></td>
			<td><xslt:value-of select="sStatus"/></td>		
			<td><xslt:value-of select="sAssignedUser"/></td>		
		</tr>
	</xslt:for-each>
</xslt:template>
<!-- Template for our "products" rule -->
<xslt:template name="Group" match="NewDataSet">
<xslt:for-each 
select="//Table[generate-id(.)=generate-id(key('NewDataSet',sAssignedUser))]">
    	<xslt:sort select="sAssignedUser" order="ascending"/>   
			<tr height="20" valign="bottom">
				<td class='group' colspan="2">
				sAssignedUser = <xslt:value-of select="sAssignedUser"/></td>
				<td colspan="2" class='total'>Group Count : <xslt:value-of 
select="../Table2[GroupVal = current()/sAssignedUser]/GroupCount"/>
				</td>
			</tr>
			<tr height="1" valign="top">
			<td vAlign="top" colSpan="4">
			<img name ="xslt" src="Images/pxl_black.gif" align ='top' height='0' 
width='100%'/></td>
			</tr>
     		<xslt:for-each select="key('NewDataSet',sAssignedUser)">
   			<xslt:sort select="sContractName"/>
	 		    <tr>
					<xslt:choose>
						<xslt:when test="position() mod 2 = 1">
							<xslt:attribute name="bgcolor"><xslt:value-of select="$color1" 
/></xslt:attribute>
						</xslt:when>
						<xslt:when test="position() mod 2 = 0">
							<xslt:attribute name="bgcolor"><xslt:value-of select="$color2" 
/></xslt:attribute>
						</xslt:when>
					</xslt:choose>
					<td>
					
					<xslt:for-each select="key('NewDataSet',RowId)">
						<xslt:choose>
							<xslt:when test="position()= $SortColumn">
								<xslt:attribute name="bgColor"><xslt:value-of 
select="$SortColor"/></xslt:attribute>
								<span class="data"><xslt:value-of select="sContractNumber"/></span>
							</xslt:when>
						</xslt:choose>
					</xslt:for-each>
					</td>
					<td>
					<span class='data'>
						<xslt:value-of select="sContractName"/>
					</span>
					</td>
					<td>
					<span class='data'>
						<xslt:value-of select="sStatus"/>
					</span>
					</td>					
					<td>
					<span class='data'>
						<xslt:value-of select="sAssignedUser"/>
					</span>
					</td>	
					<td>
					<span class='data'>
						<xslt:value-of select="startValue"/>
					</span>
					</td>	
				</tr>
    		</xslt:for-each>
				<tr height="1" valign="top">
					<td colSpan="4"><img name="xslt" src="Images/pxl_black.gif" height="0" 
align="bottom" width="100%" /></td>
				</tr>
				<xslt:variable name="values" select="key('NewDataSet',sAssignedUser)"/>
    			<tr valign="top">
    				<td colspan="4">Group Count :<xslt:value-of 
select="../Table2[GroupVal = current()/sAssignedUser]/GroupCount"/>
    				Value :
    				<xslt:value-of select="sum($values/startValue/text())"/>
    				Avg :
    				<xslt:value-of select="(sum($values/startValue)) div count($values)"/>
    				</td>
    			</tr>
	</xslt:for-each>
    <xslt:variable name="values2" 
select="NewDataSet/Table/startValue/text()"/>
    <td>
    Value :
    <xslt:value-of select="sum($values2)"/>
    Avg :
    <xslt:value-of select="(sum($values2/startValue)) div count($values2)"/>
    </td>
</xslt:template>
</xslt:stylesheet>


And here is the XML i am working...

<?xml version="1.0" encoding="utf-8" ?> 
<NewDataSet>
  <Table>
    <RowId>1</RowId>
    <sAssignedUser>Accounting</sAssignedUser>
    <sStatus>Not Started</sStatus>
    <sContractNumber>-</sContractNumber>
    <startValue>1</startValue>
	<endValue>6</endValue>
  </Table>
  <Table>
    <RowId>2</RowId>
    <sAssignedUser>Client Services</sAssignedUser>
    <sStatus>Not Started</sStatus>
    <sContractNumber>-</sContractNumber>    
    <startValue>1</startValue>
	<endValue>6</endValue>
  </Table>
  <Table>
    <RowId>4</RowId>
    <sAssignedUser>Accounting</sAssignedUser>
    <sStatus>Not Started</sStatus>
    <sContractNumber>-</sContractNumber>
    <startValue>1</startValue>
	<endValue>6</endValue>    
  </Table>
  <Table>
    <RowId>5</RowId>
    <sAssignedUser>Accounting</sAssignedUser>
    <sStatus>Not Started</sStatus>
    <sContractNumber>-</sContractNumber>
    <startValue>1</startValue>
	<endValue>6</endValue>        
  </Table>
  <Table2>
	<GroupVal>Accounting</GroupVal>
	<GroupCount>10</GroupCount>
  </Table2>
  <Table2>
	<GroupVal>Client Services</GroupVal>
	<GroupCount>3</GroupCount>
  </Table2>
</NewDataSet>




"Oleg Tkachenko [MVP]" wrote:

> xslspy wrote:
> > This is the Key used to get the Grouping effect (group by sAssignedUser)
> > 
> > <xslt:key name="NewDataSet" match="Table" use="sAssignedUser"/>
> > 
> > And the below statement is used to get the group count..
> > 
> > <xslt:variable name="values" select="key('NewDataSet',sAssignedUser)"/>
> 
> Again - this won't work if you use it as child of xsl:stylesheet. It 
> must be placed in a context where Table is context node.
> 
> -- 
> Oleg Tkachenko [XML MVP, MCAD]
> http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
> 


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent