variables - xsl string-join() 多个变量 - 只使用非空

标签 variables xslt null saxon

我想创建几个可能为空也可能不为空的 xsl:variable 然后加入它们:

<xsl:variable name="creatorType" select="replace(lib:merge(subfields/subfield[matches(@code,'[e]')],' '),'author|[.$]','')" />
<xsl:variable name="creatorAttribution" select="replace(lib:merge(subfields/subfield[matches(@code,'[j]')],' '),'[,-.]$','')" />
<xsl:variable name="creatorNameFullForm" select="replace(lib:merge(subfields/subfield[matches(@code,'[q]')],' '),'[,-()]$','')" />
<xsl:variable name="creatorAffiliation" select="replace(lib:merge(subfields/subfield[matches(@code,'[u]')],' '),'[,-.]$','')" />

string-join((xsl:sequence), 'delimiter') 看起来很合适,但也可以连接具有空值的变量。
<xsl:variable name="creatorDescriptors" select ="string-join(($creatorDates, $creatorType, $creatorAttribution, $creatorAffiliation),', ')"/>

你怎么会只有字符串连接非空xsl:变量?

我目前得到这样的东西:
  Mozart, Wolfgang Amadeus (1756–1791, Composer, , )

最佳答案

试试这个表达式(用你自己的变量名替换变量名),以便在序列中只选择非空节点

<xsl:value-of select="string-join(($a, $b, $c, $d)[. != ''],', ')"/>

关于variables - xsl string-join() 多个变量 - 只使用非空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36924888/

相关文章:

c - C 中的 limit.h *_MAX 常量的正确说明符是什么?

c++ - 稍后在程序中使用在 if else 构造内声明的变量会导致未声明的标识符错误

java - 从 XML 节点 java 生成/获取 xpath

java - 在 IBM Content Navigator 插件中使用 XSLT

c# - 如何在 C# 中设置 XSLT 以忽略错误

php - 用于比较的奇怪 MySQL 行为

sql - 如果列表中的值为空,则 NOT IN 返回 false

Java Null 解除引用垃圾收集(来自 Fortify 扫描)

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

javascript - 为什么在作为属性访问时原型(prototype)构造函数中的变量未定义?