XSLT <xsl:when> అంశం

నిర్వచనం మరియు వినియోగం

<xsl:when> అంశం <xsl:choose> అంశానికి సంబంధించిన చర్యను నిర్దేశిస్తుంది.

<xsl:when> అంశం ఒక అభివ్యక్తిని గణిస్తుంది, అనునది true ఉన్నప్పుడు నిర్దేశించిన చర్యను నిర్వహిస్తుంది.

ప్రకారం:<xsl:when> అంశం <xsl:choose> అంశం మరియు <xsl:otherwise> అంశాలతో సంబంధించిన పరిస్థితులను పరీక్షిస్తుంది.

వినియోగం

<xsl:when test="boolean-expression">
  <!-- Content: template -->
</xsl:when>

అనునాయకం

అనునాయకం విలువ వివరణ
పరీక్షించు boolean-expression అవసరం. పరీక్షించవలసిన బౌలియన్ అభివ్యక్తిని నిర్దేశిస్తుంది.

ప్రకారం

ఉదాహరణ 1

దిగువ కోడ్ సిడీ యొక్క price అధికంగా 10 ఉన్నప్పుడు artist లోపల పసుపు రంగు నిలువను చేయుతుంది:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title"/></td>
      	<xsl:choose>
          <xsl:when test="price>'10'">
            <td bgcolor="#ff00ff">
            <xsl:value-of select="artist"/></td>
          </xsl:when>
          <xsl:otherwise>
            <td><xsl:value-of select="artist"/></td>
          
        </xsl:choose>
      
      
    
  
  


查看 XML 文件查看 XSL 文件查看结果

例子 2

声明了一个名为 "color" 的变量。把它的值赋给当前元素的 color 属性。如果当前元素没有 color 属性,则 "color" 的值将是 "green":

<xsl:variable name="color">
  <xsl:choose>
    <xsl:when test="@color">
      <xsl:value-of select="@color"/>
    </xsl:when>
    <xsl:otherwise>గ్రీన్</xsl:otherwise>
  </xsl:choose>
</xsl:variable>