如何在没有来自apex:outputPanel的空span标签的情况下实现嵌套条件渲染?

twa*_*ley 7 visualforce apex-code

我试图从VisualForce页面生成干净的XSL-FO.但是,由于嵌套的apex:outputPanel标签(外部渲染=真,内部渲染=假)生成的空跨度标记,因此来自VisualForce页面的xml无效.这是一个聚焦页面,说明了问题:

<apex:page contentType="text/xml" cache="false" showHeader="false" sidebar="false">
    <root>
        There is no reason for a nested apex:outputpanel to generate a span tag like this:  

        <apex:outputPanel layout="none" rendered="true">
            <apex:outputPanel layout="none" rendered="false" />
        </apex:outputPanel>

        This breaks strict xml documents like XSL-FO.
    </root>        
</apex:page>
Run Code Online (Sandbox Code Playgroud)

该页面给出了这个xml输出:

<root>
    There is no reason for a nested apex:outputpanel to generate a span tag like this:

    <span id="j_id0:j_id3" style="display: none;"></span>

    This breaks strict xml documents like XSL-FO.
</root>
Run Code Online (Sandbox Code Playgroud)

实际上,我确实在文档中找到了一个模糊的原因:

apex:outputPanel布局属性 - 面板的布局样式.可能的值包括"block"(生成HTML div标签),"inline"(生成HTML span标签)和"none"(不生成HTML标签).如果未指定,则此值默认为"none".但是,如果layout设置为"none",则对于渲染属性设置为"false"的每个子元素,outputPanel会生成一个span标记,其中包含每个子节点的ID,并且style属性设置为"display:none" .因此,虽然内容不可见,但JavaScript仍然可以通过DOM ID访问元素.

如果我的内容类型是html或javascript,听起来很有用,但它违反了我的严格xml.所以问题是:如何在避免span标签的同时实现嵌套条件渲染?

twa*_*ley 8

将两者或仅外部切换到apex:变量,如下所示:

<apex:variable rendered="true" value="" var="tempOuter">
    <apex:outputPanel layout="none" rendered="false" />
</apex:variable>
Run Code Online (Sandbox Code Playgroud)