【问题标题】:How do I test if image exists for a field in xslt?如何测试 xslt 中的字段是否存在图像?
【发布时间】:2012-02-06 03:03:24
【问题描述】:

我有一个表单,其中字段是上传的图像,效果很好。我现在想检查该字段是否存在图像,如果不显示则默认不显示图像

我现在有

<xsl:if test="fields/field_item_main_image/data/@original = ''"><span class="noimage"></span></xsl:if><xsl:copy-of select="fields/field_item_main_image/data" />

没有图像的范围只是提供了一个无图像 png 文件,以在不存在图像时代替图像显示,但这不起作用,因为未显示默认图像,即使该字段没有分配图像.

看源码结果是

 <data></data>

我做错了什么?

附加信息

我想添加更多信息,但真的不确定您希望我添加什么来帮助我...让我知道需要什么,我会看看是否可以获得该信息以帮助我。

相关的类风格是

.noimage {display:block;width:100px;height:100px;background-image: url(../images/no-image-available.png);}

这与 SobiPro 和 Joomla 组件有关

这是表单代码

<div>               
            <xsl:for-each select="entry/fields/*">
                <xsl:if test="( name() != 'save_button' ) and ( name() != 'cancel_button' )">
                    <xsl:variable name="fieldId">
                        <xsl:value-of select="data/*/@id" />
                    </xsl:variable>
                    <div id="{$fieldId}Container">
                        <xsl:attribute name="class">
                            <xsl:choose>
                                <xsl:when test="position() mod 2">spFormRowEven</xsl:when>
                                <xsl:otherwise>spFormRowOdd</xsl:otherwise>
                            </xsl:choose>
                        </xsl:attribute>
                        <xsl:if test="string-length( fee )">
                            <div class="spFormPaymentInfo">
                                <input name="{$fieldId}Payment" id="{$fieldId}Payment" value="" type="checkbox" class="SPPaymentBox" onclick="SP_ActivatePayment( this )"/>                             
                                <label for="{$fieldId}Payment">
                                    <xsl:value-of select="fee_msg"></xsl:value-of><br/>
                                </label>
                                <div style="margin-left:20px;">
                                    <xsl:value-of select="php:function( 'SobiPro::Txt', 'TP.PAYMENT_ADD' )" />
                                </div>
                            </div>
                        </xsl:if>
                        <div class="spFormRowLeft">
                            <label for="{$fieldId}">
                                <xsl:choose>
                                    <xsl:when test="string-length( description )">
                                        <xsl:variable name="desc">
                                            <xsl:value-of select="description" />
                                        </xsl:variable>
                                        <xsl:variable name="label">
                                            <xsl:value-of select="label" />
                                        </xsl:variable>
                                        <xsl:value-of select="php:function( 'SobiPro::Tooltip', $desc, $label )" disable-output-escaping="yes"/>                                        
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="label"/>
                                    </xsl:otherwise>
                                </xsl:choose>                               
                            </label>
                        </div>                                          
                        <div class="spFormRowRight">
                            <xsl:choose>
                                <xsl:when test="data/@escaped">
                                    <xsl:value-of select="data" disable-output-escaping="yes"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:copy-of select="data/*" disable-output-escaping="yes"/>
                                </xsl:otherwise>
                            </xsl:choose>                                                   
                            <xsl:text> </xsl:text><xsl:value-of select="@suffix"/>
                        </div>
                    </div>              
                </xsl:if>           
            </xsl:for-each>
        </div>

作为输入的一部分,我的一个字段是图像字段,我要检查该字段以查看用户是否已将图像上传到该字段,如果他们随后显示该图像,如果没有则显示默认无图像。

这些有帮助吗?

GW

【问题讨论】:

  • 你是说你没有显示的 XSLT 转换,当应用于你没有显示的 XML 文档时,会产生一个你没有显示的输出,这不是你想要的输出,你没有显示?
  • @Dimitre: LOL.. user664086: 你至少需要向我们展示样式表的输入(或至少是其中的相关部分),并告诉我们你认为上下文节点在正在处理您的&lt;xsl:if&gt; 的点。一种可能性是您正在测试存在但具有空字符串值的属性,而您需要测试该属性是否不存在。但在您向我们展示输入之前,我们不会知道。
  • 谢谢大家,我想我对你的回答是我不确定我是否理解你的要求。我对此很“新”,所以对此了解甚少

标签: image xslt


【解决方案1】:

如果该字段的默认图像没有更改,那么我将在客户端执行所有这些操作。

Take a look at this answer to do that.

【讨论】:

  • 是的,我以前见过,但这不是我想要的。
猜你喜欢
  • 2021-06-26
  • 1970-01-01
  • 2011-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多