xsl string-join() multiple variables - only use non-empty

馋奶兔 提交于 2020-03-20 08:36:48

问题


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') seems like a good fit but also joins variables with empty values.

<xsl:variable name="creatorDescriptors" select ="string-join(($creatorDates, $creatorType, $creatorAttribution, $creatorAffiliation),', ')"/>

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

回答1:


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)[. != ''],', ')"/>


来源:https://stackoverflow.com/questions/36924888/xsl-string-join-multiple-variables-only-use-non-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!