Xslt 嵌套循环
嵌套循环有问题。当我尝试将该变量选回时,该变量超出范围。我明白为什么(我想),但我不知道我的选择是什么来修复它Xslt 嵌套循环,xslt,Xslt,嵌套循环有问题。当我尝试将该变量选回时,该变量超出范围。我明白为什么(我想),但我不知道我的选择是什么来修复它 <xsl:for-each select="/objects/InstalledSQLServices"> <xsl:variable name="InstalledService" select="./Property[@Name ='Name']"></xsl:variable>
<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>
以下是我最终使用的代码:
<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>
如果与当前节点匹配,我想从xml文档中的其他节点获取值。因此,如果/objects/InstalledSQLServices/Name=/objects/SqlVersion/Instance,用/objects/SqlVersion/Instance(版本、版本等)的属性填充一列回答了我自己的问题,那么这只是获得循环的问题corrected@sqlpadawan关闭它,或者发布答案并接受它,以便其他人可以从中受益:)