我遇到嵌套循环问题。当我尝试将其退出时,该变量超出了范围。我理解为什么(我认为),但我不知道我的选择是什么来解决它。
<xsl:for-each select="/objects/InstalledSQLServices">
<xsl:variable name="InstalledService" select="./Property[@Name ='Name']"></xsl:variable>
<tr>
<td align="left">
<xsl:value-of select="./Property[@Name ='DisplayName']"/>
</td>
<td align="left">
<xsl:value-of select="./Property[@Name ='Status']"/>
</td>
<xsl:for-each select="/objects/SqlVersion">
<xsl:variable name="SqlInstance" select="concat('MSSQL$',./Property[@Name ='Instance'])"></xsl:variable>
<xsl:variable name="SqlDescription">
<xsl:choose>
<xsl:when test="$InstalledService=$SqlInstance">
<xsl:value-of select="concat(./Property[@Name ='Version'],' ', ./Property[@Name ='Edition'])"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="None"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
</xsl:for-each>
<td align="left" style="color: rgb(255,0,0); font-weight: bold">
<xsl:copy-of select="$SqlDescription"/>
</td>
</tr>
</xsl:for-each>
答案 0 :(得分:0)
以下是我最终使用的代码:
<xsl:for-each select="/objects/InstalledSQLServices">
<xsl:variable name="InstalledService" select="./Property[@Name ='Name']"></xsl:variable>
<tr>
<td align="left">
<xsl:value-of select="./Property[@Name ='DisplayName']"/>
</td>
<td align="left">
<xsl:value-of select="./Property[@Name ='Status']"/>
</td>
<td align="left">
<xsl:for-each select="/objects/GetSqlVersion">
<xsl:variable name="SqlInstance" select="concat('MSSQL$',./Property[@Name ='Instance'])"></xsl:variable>
<xsl:choose>
<xsl:when test="$InstalledService=$SqlInstance">
<xsl:value-of select="concat(./Property[@Name ='Version'],' ',./Property[@Name ='Edition'],' ',./Property[@Name ='fullVer'],' ',./Property[@Name ='Level'])"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="' '"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</td>
</tr>
</xsl:for-each>