Project

Profile

Help

Support #3567 ยป problem.string-join.xsl

Nick Nunes, 2017-12-12 00:00

 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="3.0">
<xsl:template name="main">
<xsl:variable name="input" as="element(name)+">
<name>
<surname>Smith</surname>
<given-names>Bob</given-names>
</name>
<name>
<surname>Smith</surname>
<given-names>Bob</given-names>
<suffix>Jr.</suffix>
</name>
<name>
<surname>Smith</surname>
<given-names>Bob</given-names>
<suffix>III</suffix>
</name>
</xsl:variable>
<xsl:apply-templates select="$input"/>
</xsl:template>
<!-- This code works in 9.5 and fails in 9.7 -->
<xsl:template match="name">
<xsl:variable name="suffix-join" as="xs:string?"
select="if (suffix) then
if (matches(suffix, '^[CDILMVX]+\.?$'))
then ' ' else ', '
else ()" />
<xsl:value-of select="string-join((string-join((given-names, surname), ' '), suffix), $suffix-join)"/>
</xsl:template>
<!-- This code works in 9.7 -->
<!--<xsl:template match="name">
<xsl:variable name="suffix-join" as="xs:string"
select="if (suffix) then
if (matches(suffix, '^[CDILMVX]+\.?$'))
then ' ' else ', '
else ''" />
<xsl:value-of select="string-join((string-join((given-names, surname), ' '), string(suffix)), $suffix-join)"/>
</xsl:template>-->
</xsl:stylesheet>
    (1-1/1)