问题
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