除了 Dimitre 的确切答案之外,您还可以使用此样式表中的一些模式:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="Client/*" name="space-capital">
<xsl:param name="pLetters"
select="translate(name(),'qwertyuiopasdfghjklzxcvbnm','')"/>
<xsl:param name="pString" select="name()"/>
<xsl:param name="pOut" select="''"/>
<xsl:choose>
<xsl:when test="$pString != ''">
<xsl:variable name="vFirst" select="substring($pString,1,1)"/>
<xsl:call-template name="space-capital">
<xsl:with-param name="pLetters" select="$pLetters"/>
<xsl:with-param name="pString"
select="substring($pString,2)"/>
<xsl:with-param name="pOut"
select="concat($pOut,
substring(' ',1,contains($pLetters,
$vFirst)
and
$pOut != ''),
$vFirst
)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($pOut,' : ',.,'
')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
有了这个正确的输入:
<ClientArray>
<Client>
<LastName>Aanonsen</LastName>
<FirstName>Fred</FirstName>
<AdditionalRemarks>Something</AdditionalRemarks>
</Client>
</ClientArray>
输出:
Last Name : Aanonsen
First Name : Fred
Additional Remarks : Something
在 XPath 2.0 中:
string-join(/*/*/*/concat(
(: This is the expression you need :)
replace(name(),
'(\P{Lu})(\p{Lu})',
'$1 $2'),
(: the rest is just to mimic the result :)
' : ',.),
'
')