簡體   English   中英

XSLT選擇復選框基於節點值

[英]XSLT select check box based on node value

我正在嘗試創建xslt,我需要根據XML節點值選中或取消選中復選框。 如果descr節點包含或等於“ Student”,我想選中“學生”復選框,否則應取消選中該復選框。 如果decr節點包含學院或等於學院,則應選中“學院”復選框,否則應取消選中該復選框。

我的XML是

<WI>
  <Wi>
    <last_nam>CLARK                         </last_nam>
    <first_nam>HUNTER              </first_nam>
    <wit_flag>1</wit_flag>
    <descr>Faculty      </descr>
  </Wi>
</WI>
<WI>
  <Wi>
    <last_nam>MCMENAMIN                     </last_nam>
    <first_nam>COLLIN              </first_nam>
    <wit_flag>1</wit_flag>
    <descr>Student      </descr>
  </Wi>
</WI>

XSLT是

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <head>
      </head>
      <body>
        <div class="container">
          <table border="1">
            <tr>
              <td colspan="2">
                Person
                <br />
                <xsl:value-of select="WI/Wi/lat_nam" />
              </td>
            </tr>
            <tr>
              <td>
                <input id="student_flag" name="student_flag" type="checkbox"
                  value="1">
                  <xsl:choose>
                    <xsl:when test="WI/Wi/descr[contains(text(),Student]">
                      <xsl:attribute name="value">1</xsl:attribute>
                      <xsl:attribute name="checked">true</xsl:attribute>
                      <xsl:value-of select="'Student'" />
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:attribute name="value">0</xsl:attribute>
                      <xsl:value-of select="'Student'" />
                    </xsl:otherwise>
                  </xsl:choose>
                </input>
              </td>
              <td>
                <input id="Faculty_flag" name="Faculty_flag" type="checkbox"
                  value="1">
                  <xsl:choose>
                    <xsl:when test="WI/Wi/descr[contains(text(),Faculty]">
                      <xsl:attribute name="value">1</xsl:attribute>
                      <xsl:attribute name="checked">true</xsl:attribute>
                      <xsl:value-of select="'Faculty'" />
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:attribute name="value">0</xsl:attribute>
                      <xsl:value-of select="'Faculty'" />
                    </xsl:otherwise>
                  </xsl:choose>
                </input>
              </td>
            </tr>
          </table>
        </div>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

嘗試設置checked="checked"而不是checked="true" 這就是HTML中布爾屬性的工作方式...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM