将测试插入 xslt 文件以确保没有空白值
我有以下 XSLT 文件,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" xmlns:UCommentLibrary="urn:UCommentLibrary" xmlns:uForum="urn:uForum" xmlns:uForum.raw="urn:uForum.raw"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary UCommentLibrary uForum uForum.raw ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="blognode" select="umbraco.library:GetXmlNodeById(1187)" />
<xsl:variable name="today" select="umbraco.library:CurrentDate()" />
<xsl:variable name="later" select="umbraco.library:DateAdd($today, 'd', -3)" />
<xsl:variable name="count" select="4" />
<xsl:template match="/">
<div id="slider" class="news_banner" >
<xsl:for-each select="$blognode/ancestor-or-self::*//BlogPost [@isDoc and umbraco.library:DateGreaterThanOrEqual(PostDate, $later) ]">
<xsl:sort select="pageViewCount" data-type="number" order="descending" />
<xsl:if test="blogImage != ''">
<xsl:variable name="crop" select="umbraco.library:GetMedia(blogImage, 0)/crops/crops/crop [@name='NewsBanner']" />
<xsl:if test="$crop/@url != '' and position() <= $count" >
<a href="{umbraco.library:NiceUrl(@id)}"><img src="{$crop/@url}" alt="{@nodeName}" title="#htmlcaption{@id}" /></a>
</xsl:if>
</xsl:if>
</xsl:for-each>
</div>
<xsl:for-each select="$blognode/ancestor-or-self::*//BlogPost [@isDoc and umbraco.library:DateGreaterThanOrEqual(PostDate, $later) ]">
<xsl:sort select="pageViewCount" data-type="number" order="descending" />
<xsl:if test="blogImage != ''" >
<xsl:variable name="crop" select="umbraco.library:GetMedia(blogImage, 0)/crops/crops/crop [@name='NewsBanner']" />
<xsl:if test="$crop/@url != '' and position() <= $count">
<div id="htmlcaption{@id}" class="nivo-html-caption"><xsl:value-of select="@nodeName" /> - <a href="{umbraco.library:NiceUrl(@id)}">Full Story...</a></div>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
如何在此处插入测试以确保条目不为空。
I have the following XSLT file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" xmlns:UCommentLibrary="urn:UCommentLibrary" xmlns:uForum="urn:uForum" xmlns:uForum.raw="urn:uForum.raw"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary UCommentLibrary uForum uForum.raw ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="blognode" select="umbraco.library:GetXmlNodeById(1187)" />
<xsl:variable name="today" select="umbraco.library:CurrentDate()" />
<xsl:variable name="later" select="umbraco.library:DateAdd($today, 'd', -3)" />
<xsl:variable name="count" select="4" />
<xsl:template match="/">
<div id="slider" class="news_banner" >
<xsl:for-each select="$blognode/ancestor-or-self::*//BlogPost [@isDoc and umbraco.library:DateGreaterThanOrEqual(PostDate, $later) ]">
<xsl:sort select="pageViewCount" data-type="number" order="descending" />
<xsl:if test="blogImage != ''">
<xsl:variable name="crop" select="umbraco.library:GetMedia(blogImage, 0)/crops/crops/crop [@name='NewsBanner']" />
<xsl:if test="$crop/@url != '' and position() <= $count" >
<a href="{umbraco.library:NiceUrl(@id)}"><img src="{$crop/@url}" alt="{@nodeName}" title="#htmlcaption{@id}" /></a>
</xsl:if>
</xsl:if>
</xsl:for-each>
</div>
<xsl:for-each select="$blognode/ancestor-or-self::*//BlogPost [@isDoc and umbraco.library:DateGreaterThanOrEqual(PostDate, $later) ]">
<xsl:sort select="pageViewCount" data-type="number" order="descending" />
<xsl:if test="blogImage != ''" >
<xsl:variable name="crop" select="umbraco.library:GetMedia(blogImage, 0)/crops/crops/crop [@name='NewsBanner']" />
<xsl:if test="$crop/@url != '' and position() <= $count">
<div id="htmlcaption{@id}" class="nivo-html-caption"><xsl:value-of select="@nodeName" /> - <a href="{umbraco.library:NiceUrl(@id)}">Full Story...</a></div>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
How can I insert tests in here to insure that the entries are not blank.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
取决于“空白”的含义。
这是确定特定表达式的值(为方便起见,此处表示为
$var
)是否仅由空格组成的通用方法:这可以如果写成等价的,则更加通用和灵活:
如果我们对“空白”有不同的理解,则可以使用上面的内容来检查
$var
是否不为空应该是的意思。例如:测试
$var
是否包含除空白字符(空格、换行符和制表符)和“不可破坏的空白字符”(O;
)Depends on what is meant by "blank".
Here is a general way to determine if the value of a particular expression (here denoted as
$var
for convenience) doesn't consist only of whitespace:This can be made more general and flexible if written as the equivalent:
The above can be used to check for
$var
not being blank if we have a different understanding of what "blank" should mean. For example:tests if
$var
contains any other characters beside the white-space characters (space, new-line carriage return and tab) and the "non-breakable white-space character" (O;
)