根据条件设置节点值
问题描述:
<?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
答
ServerName ='true'" < xsl:apply-templates/ > 跨度> < xsl:value-of 选择 ="
ServerName='true'"> <xsl:apply-templates/> <xsl:value-of select="
RowCount" / < /xsl:何时 > < xsl:否则 > < xsl:apply-templates/ > 跨度> < xsl:value-of 选择 =" / > < /xsl:otherwise > < /xsl:choose > < /xsl:template > 但这会将值设置为Null,如< RowCount > < /RowCount > ; 谢谢 Ratz
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
您如何声明变量?对于您的真实情况,这应该可以正常工作:
How are you declaring your variables? This should work correctly for your true case:
<xsl:variable name="ServerName">true</xsl:variable>
<xsl:variable name="RowCount">1000</xsl:variable>
可能是错误的情况,为您提供了null,在这种情况下,请尝试以下操作:
It may be the false case that''s giving you null, in which case, try this:
<xsl:value-of select="."/>