开发者

XSLT display email if present

I am working on a page that displays contact email and phone number at the bottom of the page. The code I'm using now is:

email: <a href="mailto:{//footer_email}">
          <xsl:value-of select="//footer_email"/></a>

I just ran across a page that doesn't have an email at the bottom, so when I view the XML document it shows "email: " with nothing after it.

My question is, how would I specify if there is an email present, then display the entire thing, but if there isn't an email present, then don't display it at 开发者_如何学Pythonall.


You don't need any conditional logic at all.

Simply use:

<xsl:apply-templates mode="mailLink" select="(//footer_email)[1]"/>

where you have this template:

<xsl:template match="footer_email" mode="mailLink">
   email: <a href="mailto:{.}"><xsl:value-of select="."/></a>     
</xsl:template>


Using xsl:if you check whether there is //footer_email or not:

<xsl:if test="//footer_email">
   email: <a href="mailto:{//footer_email}"><xsl:value-of select="//footer_email"/></a>
</xsl:if>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜