根据条件设置节点值

根据条件设置节点值

本文介绍了根据条件设置节点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?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

推荐答案



<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="."/>


这篇关于根据条件设置节点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 01:17