2011-11-23 191 views
0

我遇到了嵌套循环的问题。当我尝试将其选回时,该变量超出范围。我明白为什么(我认为),但我不知道我的选择是要解决它。Xsl嵌套循环

  <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

我想抓住从XML文档中的不同节点的值,如果没有当前节点的匹配。因此,如果/ objects/InstalledSQLServices/Name =/objects/SqlVersion/Instance,使用来自/ objects/SqlVersion/Instance(版本,版本等)的属性填充一个列。 – sqlpadawan

+0

回答我自己的问题,这只是一个问题获取循环更正 – sqlpadawan

+0

@sqlpadawan要么关闭它,要么发布答案并接受它,以便其他人可以从中受益:) – FailedDev

回答

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="'&#160;'"/> 
        </xsl:otherwise> 
        </xsl:choose> 
       </xsl:for-each> 
       </td> 
      </tr> 
      </xsl:for-each>