Click here to Skip to main content
16,016,623 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
XML
<?xml version="1.0" encoding="utf-8"?>
<Project >
<ServerName>2712</ServerName>
<Name1><ServerName>2712</ServerName>
<Tables>
	<Table>
		<Name>Table1</Name>
        <TableType>Generated</TableType>
		<DataVersion version="1" type="PopulationDetails">
        <PopulationType>RowCount</PopulationType>
        <RowCount>2712</RowCount>
        <ProportionTableExists>False</ProportionTableExists>
        <Proportion>0</Proportion>
        <TimeToPopulate>0</TimeToPopulate>
	</Table>
	<Table>
		<Name>Table2</Name>
        <TableType>Generated</TableType>
		<DataVersion version="1" type="PopulationDetails">
        <PopulationType>RowCount</PopulationType>
        <RowCount>2712</RowCount>
        <ProportionTableExists>False</ProportionTableExists>
        <Proportion>0</Proportion>
        <TimeToPopulate>0</TimeToPopulate>
	</Table>
	<Table>
		<Name>Table3</Name>
        <TableType>Generated</TableType>
		<DataVersion version="1" type="PopulationDetails">
        <PopulationType>RowCount</PopulationType>
        <RowCount>2712</RowCount>
        <ProportionTableExists>False</ProportionTableExists>
        <Proportion>0</Proportion>
        <TimeToPopulate>0</TimeToPopulate>
	</Table>
</Tables>
</Name1>
<Name2>
<Name1><ServerName>2712</ServerName></Name1></Name2>
</Project>

Need help in writing XSLT
       I want to change all the RowCount Values to 1000. based on the parameter if it is true else it should not change the value.
I tried writing this
<xsl:template match="Tables/Table/RowCount/text()">
      <xsl:choose>
        <xsl:when test="$ServerName='true'">
          <xsl:apply-templates/>
          <xsl:value-of select="$RowCount" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates/>
          <xsl:value-of select="text()" />          
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

But this is setting the value as Null as in <RowCount></RowCount>

Thanks 
Ratz
Posted
Updated 24-Apr-12 20:17pm
v3

1 solution

How are you declaring your variables? This should work correctly for your true case:
HTML
<xsl:variable name="ServerName">true</xsl:variable>
  <xsl:variable name="RowCount">1000</xsl:variable>

It may be the false case that's giving you null, in which case, try this:
HTML
<xsl:value-of select="."/>
 
Share this answer
 
v2
Comments
RatishPillai 26-Apr-12 4:23am    
Great !!

Thanks, It Worked :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900