【问题标题】:XSLT boolean valueXSLT 布尔值
【发布时间】:2010-07-27 13:04:36
【问题描述】:

我尝试在此处搜索我的问题,但未成功。

<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 的真值或假值:

<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>

【问题讨论】:

    标签: xslt boolean


    【解决方案1】:

    比较值“真”和“假”以及“1”和“0”:

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

    因为xs:boolean 元素的可能值就是这四个值。

    在 XPath 2.0 中,您可以使用 boolean() 函数来转换它们。由于这对您不起作用,我假设您使用的是 XPath 1.0。

    【讨论】:

    • 像这样$all_events[boolean(g:active) = 1] ?
    • 没有。没有必要进行这样的比较。 $all_events[boolean(g:active)] 会很好。如果您需要比较某些东西,请与实际的布尔值进行比较,例如:$all_events[boolean(g:active) = true()]。同样,这不是必需的。
    • 我相信我必须指定它是真还是假,因为现在复选框是否被选中。添加true() 的事件无效。
    • 你给我一份你的源文件样本怎么样,这样我就可以看到你在处理什么?
    • 我从我的 XSD 和 XSLT 添加了部分。它们与 Alfresco CMS 作为 Web 表单绑定并创建复选框。您指的是哪个源文档?
    猜你喜欢
    • 2020-08-18
    • 2017-04-08
    • 2018-07-28
    • 2011-04-13
    • 2011-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多