xsl:choose / xsl:否则不适合我

时间:2016-02-15 18:10:09

标签: xml xslt

如果标记HOST_NAME不是空白,则下面有效,但是当标记ASSET_TYPE不是空白时,&#39;否则&#39;没有返回<xsl:variable name="vhostname"> <xsl:choose> <xsl:when test="ASSET/HOST_NAME !=''"> <xsl:value-of select="ASSET/HOST_NAME" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="/CHECKLIST/ASSET/ASSET_TYPE" /> </xsl:otherwise> </xsl:choose> </xsl:variable> 标记。我觉得这一定很简单,但无论我尝试什么,我都看不到它:

<CHECKLIST>
 <ASSET>
  <ASSET_TYPE>Computing</ASSET_TYPE>
  <HOST_NAME></HOST_NAME>
  <HOST_IP></HOST_IP>
  <HOST_MAC></HOST_MAC>
  <HOST_GUID></HOST_GUID>
  <HOST_FQDN></HOST_FQDN>
  <TECH_AREA></TECH_AREA>
  <TARGET_KEY></TARGET_KEY>
 </ASSET>
</CHECKLIST>

XML是:

public static void main(String[] args) throws IOException {
        WebDriver driver=new FirefoxDriver();
        driver.manage().window().maximize();
        driver.get("http://automationpractice.com/index.php");
        WebElement element=driver.findElement(By.cssSelector("a[title='Contact Us']"));
        System.out.println(element.getText());
        element.getScreenshotAs(OutputType.FILE);
        File destination=new File("Image.png");
        FileUtils.copyFile(null, destination);
    }

1 个答案:

答案 0 :(得分:0)

尝试修改您的代码:

<xsl:variable name="vhostname">
 <xsl:choose>
  <xsl:when test="string(ASSET/HOST_NAME/text())">
   <xsl:value-of select="ASSET/HOST_NAME/text()" />
  </xsl:when>
  <xsl:otherwise>
   <xsl:value-of select="ASSET/ASSET_TYPE/text()" />
  </xsl:otherwise>
 </xsl:choose>
</xsl:variable>