将测试插入 xslt 文件以确保没有空白值

发布于 2024-11-09 17:31:28 字数 3121 浏览 0 评论 0原文

我有以下 XSLT 文件,

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<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() &lt;= $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() &lt;= $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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

垂暮老矣 2024-11-16 17:31:28

如何在这里插入测试
确保条目不为空

取决于“空白”的含义。

这是确定特定表达式的值(为方便起见,此处表示为 $var)是否仅由空格组成的通用方法

string-length(normalize-space($var)) > 0

这可以如果写成等价的,则更加通用和灵活:

string-length(translate($var, ' 
	')) > 0

如果我们对“空白”有不同的理解,则可以使用上面的内容来检查 $var 是否不为空应该是的意思。例如:

string-length(translate($var, ' 
	 ')) > 0

测试 $var 是否包含除空白字符(空格、换行符和制表符)和“不可破坏的空白字符”(O;)

How can I insert tests in here to
insure that the entries are not blank

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:

string-length(normalize-space($var)) > 0

This can be made more general and flexible if written as the equivalent:

string-length(translate($var, ' 
	')) > 0

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:

string-length(translate($var, ' 
	 ')) > 0

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文