本文介绍了xsl string-join() 多个变量 - 仅使用非空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建几个 xsl:variable 可能是也可能不是 null 然后加入它们:
I'd like to create several xsl:variable that may or may not be null then join them:
<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') 看起来很合适,但也连接带有空值的变量.
string-join((xsl:sequence), 'delimiter') seems like a good fit but also joins variables with empty values.
<xsl:variable name="creatorDescriptors" select ="string-join(($creatorDates, $creatorType, $creatorAttribution, $creatorAffiliation),', ')"/>
你怎么会只有字符串连接非空 xsl:variables?
How would you have it only string-join non-null xsl:variables?
我目前得到这样的信息:
I'm currently getting something like this:
Mozart, Wolfgang Amadeus (1756–1791, Composer, , )
推荐答案
试试这个表达式(用你自己的变量名替换变量名),这样只会选择序列中的非空节点
Try this expression instead (replacing the variable names with your own variable names), so that only the non-empty nodes are selected in the sequence
<xsl:value-of select="string-join(($a, $b, $c, $d)[. != ''],', ')"/>
这篇关于xsl string-join() 多个变量 - 仅使用非空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!