XSLT布尔值

问题描述:

我试着在这里搜索我的问题,并没有成功。XSLT布尔值

<xsl:for-each select="$all_events[g:active = 1]"> 
     <xsl:sort select="g:event_date" order="descending"/> 
     <xsl:variable name="fileName"><xsl:value-of select="fn:replaceAll(string(@alf:file_name), '.xml', '.html')"/></xsl:variable> 
     <xsl:variable name="fileURL"><xsl:value-of select="concat('/events/', $fileName)" /></xsl:variable> 
     <xsl:variable name="fileDate"><xsl:value-of select="g:event_date" /></xsl:variable> 
     <xsl:variable name="date"><xsl:value-of select="substring($fileDate, 6, 2)" /></xsl:variable> 
     <li><a href="{$fileURL}"><xsl:value-of select="g:event_title"/></a></li> 
    </xsl:for-each> 
    </ul><br/> 
    <xsl:for-each select="$all_events[g:body/g:current = 1]"> 
     <xsl:for-each select="g:body"> 
      <h2 class="normal"><xsl:value-of select="g:sub_title" /></h2> 
       <xsl:for-each select="g:paragraphs"> 
        <xsl:value-of select="g:paragraph" disable-output-escaping="yes"/> 
       </xsl:for-each> 
     </xsl:for-each> 
    </xsl:for-each> 

我有两个的for-each语句检查我的XSD为true或false值:

<xs:simpleType name="confirm"> 
     <xs:restriction base="xs:boolean"/> 
</xs:simpleType> 

<xs:element name="active" type="g:confirm" minOccurs="0"/> 
<xs:element name="current" type="g:confirm" minOccurs="0"/> 

上面没有为我工作。我也试过true()/false(),这似乎也失败了。

我错过了一些明显的东西吗?

编辑: 布尔值是在Alfresco CMS中的复选框,所以我不能简单地检查它的存在,而是它是真是假。

<xs:simpleType name="confirm"> 
     <xs:restriction base="xs:boolean"/> 
</xs:simpleType> 
<xs:element name="content"> 
    <xs:complexType> 
     <xs:sequence> 
      <xs:element name="page_title" type="xs:normalizedString" minOccurs = "0"> 
       <xs:annotation> 
        <xs:appinfo> 
         <alf:appearance>title</alf:appearance> 
        </xs:appinfo> 
       </xs:annotation> 
      </xs:element> 
      <xs:element name="event_title" type="xs:normalizedString" minOccurs = "0"> 
       <xs:annotation> 
        <xs:appinfo> 
         <alf:appearance>title</alf:appearance> 
        </xs:appinfo> 
       </xs:annotation> 
      </xs:element> 
      <xs:element name="active" type="g:confirm" minOccurs="0"/> 
      <xs:element name="event_date" type="xs:date" /> 
      <xs:element name="body" minOccurs="0" maxOccurs="unbounded"> 
       <xs:complexType> 
        <xs:sequence> 
         <xs:element name="sub_title" type="xs:normalizedString" minOccurs = "0"> 
          <xs:annotation> 
           <xs:appinfo> 
            <alf:appearance>title</alf:appearance> 
           </xs:appinfo> 
          </xs:annotation> 
         </xs:element> 
         <xs:element name="current" type="g:confirm" minOccurs="0"/> 
         <xs:element name="paragraphs" minOccurs="0" maxOccurs="unbounded"> 
          <xs:complexType> 
           <xs:sequence> 
            <xs:element name="paragraph" type="xs:string" minOccurs = "0"> 
             <xs:annotation> 
              <xs:appinfo> 
               <alf:appearance>custom</alf:appearance> 
              </xs:appinfo> 
             </xs:annotation> 
            </xs:element> 
           </xs:sequence> 
          </xs:complexType> 
         </xs:element> 
        </xs:sequence> 
       </xs:complexType> 
      </xs:element> 
     </xs:sequence> 
    </xs:complexType> 
</xs:element> 
</xs:schema> 

针对比较的值“真”和“假”,以及“1”和“0”:

$all_events[(g:active = 'true') or (g:active = 1)] 

因为一个xs:boolean元件的可能的值是这四个值。

在XPath 2.0中,您可以使用boolean()函数来投射它们。由于这不适合你,我假设你正在使用XPath 1.0。

+0

所以像这样'$ all_events [boolean(g:active)= 1]'? – balexander 2010-07-27 13:11:12

+0

不需要这样的比较。 '$ all_events [boolean(g:active)]'会做得很好。如果您需要比较某些内容,请与实际布尔值进行比较,如下所示:'$ all_events [boolean(g:active)= true()]'。再次,这不是必要的。 – Welbog 2010-07-27 13:12:21

+0

我相信我必须指定它是真是假,因为现在是否复选框被选中或不显示。添加“true()”的事件不起作用。 – balexander 2010-07-27 13:18:12